Skip to content

Commit ddf49d5

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/trace: Add TRACE support for CXL media-error records
CXL devices may support the retrieval of a device poison list. Add a new trace event that the CXL subsystem may use to log the media-error records returned in the poison list. Log each media-error record as a cxl_poison trace event of type 'List'. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/de6196f5269483d886ab1834744f82d27189a666.1681838291.git.alison.schofield@intel.com Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent ed83f7c commit ddf49d5

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

drivers/cxl/core/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ int cxl_memdev_init(void);
6464
void cxl_memdev_exit(void);
6565
void cxl_mbox_init(void);
6666

67+
enum cxl_poison_trace_type {
68+
CXL_POISON_TRACE_LIST,
69+
};
70+
6771
#endif /* __CXL_CORE_H__ */

drivers/cxl/core/mbox.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,10 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
11901190
if (rc)
11911191
break;
11921192

1193-
/* TODO TRACE the media error records */
1193+
for (int i = 0; i < le16_to_cpu(po->count); i++)
1194+
trace_cxl_poison(cxlmd, cxlr, &po->record[i],
1195+
po->flags, po->overflow_ts,
1196+
CXL_POISON_TRACE_LIST);
11941197

11951198
/* Protect against an uncleared _FLAG_MORE */
11961199
nr_records = nr_records + le16_to_cpu(po->count);

drivers/cxl/core/trace.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#define _CXL_EVENTS_H
88

99
#include <linux/tracepoint.h>
10+
#include <linux/pci.h>
1011
#include <asm-generic/unaligned.h>
1112

1213
#include <cxl.h>
1314
#include <cxlmem.h>
15+
#include "core.h"
1416

1517
#define CXL_RAS_UC_CACHE_DATA_PARITY BIT(0)
1618
#define CXL_RAS_UC_CACHE_ADDR_PARITY BIT(1)
@@ -600,6 +602,98 @@ TRACE_EVENT(cxl_memory_module,
600602
)
601603
);
602604

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_ts, enum cxl_poison_trace_type trace_type),
644+
645+
TP_ARGS(cxlmd, region, record, flags, overflow_ts, trace_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, trace_type)
652+
__string(region, region)
653+
__field(u64, overflow_ts)
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_ts = cxl_poison_overflow(flags, overflow_ts);
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->trace_type = trace_type;
670+
__entry->flags = flags;
671+
if (region) {
672+
__assign_str(region, dev_name(&region->dev));
673+
memcpy(__entry->uuid, &region->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 trace_type=%s region=%s " \
681+
"region_uuid=%pU dpa=0x%llx dpa_length=0x%x source=%s " \
682+
"flags=%s overflow_time=%llu",
683+
__get_str(memdev),
684+
__get_str(host),
685+
__entry->serial,
686+
show_poison_trace_type(__entry->trace_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_ts
694+
)
695+
);
696+
603697
#endif /* _CXL_EVENTS_H */
604698

605699
#define TRACE_INCLUDE_FILE trace

0 commit comments

Comments
 (0)