Skip to content

Commit 6aec001

Browse files
AlisonSchofielddavejiang
authored andcommitted
cxl/core: Add region info to cxl_general_media and cxl_dram events
User space may need to know which region, if any, maps the DPAs (device physical addresses) reported in a cxl_general_media or cxl_dram event. Since the mapping can change, the kernel provides this information at the time the event occurs. This informs user space that at event <timestamp> this <region> mapped this <DPA> to this <HPA>. Add the same region info that is included in the cxl_poison trace event: the DPA->HPA translation, region name, and region uuid. The new fields are inserted in the trace event and no existing fields are modified. If the DPA is not mapped, user will see: hpa=ULLONG_MAX, region="", and uuid=0 This work must be protected by dpa_rwsem & region_rwsem since it is looking up region mappings. Signed-off-by: Alison Schofield <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/dd8d708b7a7ebfb64a27020a5eb338091336b34d.1714496730.git.alison.schofield@intel.com Signed-off-by: Dave Jiang <[email protected]>
1 parent 86954ff commit 6aec001

File tree

3 files changed

+75
-15
lines changed

3 files changed

+75
-15
lines changed

drivers/cxl/core/mbox.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,38 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
842842
enum cxl_event_type event_type,
843843
const uuid_t *uuid, union cxl_event *evt)
844844
{
845-
if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
846-
trace_cxl_general_media(cxlmd, type, &evt->gen_media);
847-
else if (event_type == CXL_CPER_EVENT_DRAM)
848-
trace_cxl_dram(cxlmd, type, &evt->dram);
849-
else if (event_type == CXL_CPER_EVENT_MEM_MODULE)
845+
if (event_type == CXL_CPER_EVENT_MEM_MODULE) {
850846
trace_cxl_memory_module(cxlmd, type, &evt->mem_module);
851-
else
847+
return;
848+
}
849+
if (event_type == CXL_CPER_EVENT_GENERIC) {
852850
trace_cxl_generic_event(cxlmd, type, uuid, &evt->generic);
851+
return;
852+
}
853+
854+
if (trace_cxl_general_media_enabled() || trace_cxl_dram_enabled()) {
855+
u64 dpa, hpa = ULLONG_MAX;
856+
struct cxl_region *cxlr;
857+
858+
/*
859+
* These trace points are annotated with HPA and region
860+
* translations. Take topology mutation locks and lookup
861+
* { HPA, REGION } from { DPA, MEMDEV } in the event record.
862+
*/
863+
guard(rwsem_read)(&cxl_region_rwsem);
864+
guard(rwsem_read)(&cxl_dpa_rwsem);
865+
866+
dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
867+
cxlr = cxl_dpa_to_region(cxlmd, dpa);
868+
if (cxlr)
869+
hpa = cxl_trace_hpa(cxlr, cxlmd, dpa);
870+
871+
if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
872+
trace_cxl_general_media(cxlmd, type, cxlr, hpa,
873+
&evt->gen_media);
874+
else if (event_type == CXL_CPER_EVENT_DRAM)
875+
trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
876+
}
853877
}
854878
EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
855879

drivers/cxl/core/trace.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ TRACE_EVENT(cxl_generic_event,
316316
TRACE_EVENT(cxl_general_media,
317317

318318
TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
319-
struct cxl_event_gen_media *rec),
319+
struct cxl_region *cxlr, u64 hpa, struct cxl_event_gen_media *rec),
320320

321-
TP_ARGS(cxlmd, log, rec),
321+
TP_ARGS(cxlmd, log, cxlr, hpa, rec),
322322

323323
TP_STRUCT__entry(
324324
CXL_EVT_TP_entry
@@ -330,10 +330,13 @@ TRACE_EVENT(cxl_general_media,
330330
__field(u8, channel)
331331
__field(u32, device)
332332
__array(u8, comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE)
333-
__field(u16, validity_flags)
334333
/* Following are out of order to pack trace record */
334+
__field(u64, hpa)
335+
__field_struct(uuid_t, region_uuid)
336+
__field(u16, validity_flags)
335337
__field(u8, rank)
336338
__field(u8, dpa_flags)
339+
__string(region_name, cxlr ? dev_name(&cxlr->dev) : "")
337340
),
338341

339342
TP_fast_assign(
@@ -354,18 +357,28 @@ TRACE_EVENT(cxl_general_media,
354357
memcpy(__entry->comp_id, &rec->component_id,
355358
CXL_EVENT_GEN_MED_COMP_ID_SIZE);
356359
__entry->validity_flags = get_unaligned_le16(&rec->validity_flags);
360+
__entry->hpa = hpa;
361+
if (cxlr) {
362+
__assign_str(region_name, dev_name(&cxlr->dev));
363+
uuid_copy(&__entry->region_uuid, &cxlr->params.uuid);
364+
} else {
365+
__assign_str(region_name, "");
366+
uuid_copy(&__entry->region_uuid, &uuid_null);
367+
}
357368
),
358369

359370
CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' " \
360371
"descriptor='%s' type='%s' transaction_type='%s' channel=%u rank=%u " \
361-
"device=%x comp_id=%s validity_flags='%s'",
372+
"device=%x comp_id=%s validity_flags='%s' " \
373+
"hpa=%llx region=%s region_uuid=%pUb",
362374
__entry->dpa, show_dpa_flags(__entry->dpa_flags),
363375
show_event_desc_flags(__entry->descriptor),
364376
show_mem_event_type(__entry->type),
365377
show_trans_type(__entry->transaction_type),
366378
__entry->channel, __entry->rank, __entry->device,
367379
__print_hex(__entry->comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE),
368-
show_valid_flags(__entry->validity_flags)
380+
show_valid_flags(__entry->validity_flags),
381+
__entry->hpa, __get_str(region_name), &__entry->region_uuid
369382
)
370383
);
371384

@@ -400,9 +413,9 @@ TRACE_EVENT(cxl_general_media,
400413
TRACE_EVENT(cxl_dram,
401414

402415
TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
403-
struct cxl_event_dram *rec),
416+
struct cxl_region *cxlr, u64 hpa, struct cxl_event_dram *rec),
404417

405-
TP_ARGS(cxlmd, log, rec),
418+
TP_ARGS(cxlmd, log, cxlr, hpa, rec),
406419

407420
TP_STRUCT__entry(
408421
CXL_EVT_TP_entry
@@ -417,10 +430,13 @@ TRACE_EVENT(cxl_dram,
417430
__field(u32, nibble_mask)
418431
__field(u32, row)
419432
__array(u8, cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE)
433+
__field(u64, hpa)
434+
__field_struct(uuid_t, region_uuid)
420435
__field(u8, rank) /* Out of order to pack trace record */
421436
__field(u8, bank_group) /* Out of order to pack trace record */
422437
__field(u8, bank) /* Out of order to pack trace record */
423438
__field(u8, dpa_flags) /* Out of order to pack trace record */
439+
__string(region_name, cxlr ? dev_name(&cxlr->dev) : "")
424440
),
425441

426442
TP_fast_assign(
@@ -444,12 +460,21 @@ TRACE_EVENT(cxl_dram,
444460
__entry->column = get_unaligned_le16(rec->column);
445461
memcpy(__entry->cor_mask, &rec->correction_mask,
446462
CXL_EVENT_DER_CORRECTION_MASK_SIZE);
463+
__entry->hpa = hpa;
464+
if (cxlr) {
465+
__assign_str(region_name, dev_name(&cxlr->dev));
466+
uuid_copy(&__entry->region_uuid, &cxlr->params.uuid);
467+
} else {
468+
__assign_str(region_name, "");
469+
uuid_copy(&__entry->region_uuid, &uuid_null);
470+
}
447471
),
448472

449473
CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' descriptor='%s' type='%s' " \
450474
"transaction_type='%s' channel=%u rank=%u nibble_mask=%x " \
451475
"bank_group=%u bank=%u row=%u column=%u cor_mask=%s " \
452-
"validity_flags='%s'",
476+
"validity_flags='%s' " \
477+
"hpa=%llx region=%s region_uuid=%pUb",
453478
__entry->dpa, show_dpa_flags(__entry->dpa_flags),
454479
show_event_desc_flags(__entry->descriptor),
455480
show_mem_event_type(__entry->type),
@@ -458,7 +483,8 @@ TRACE_EVENT(cxl_dram,
458483
__entry->bank_group, __entry->bank,
459484
__entry->row, __entry->column,
460485
__print_hex(__entry->cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE),
461-
show_dram_valid_flags(__entry->validity_flags)
486+
show_dram_valid_flags(__entry->validity_flags),
487+
__entry->hpa, __get_str(region_name), &__entry->region_uuid
462488
)
463489
);
464490

include/linux/cxl-event.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,21 @@ struct cxl_event_mem_module {
9191
u8 reserved[0x3d];
9292
} __packed;
9393

94+
/*
95+
* General Media or DRAM Event Common Fields
96+
* - provides common access to phys_addr
97+
*/
98+
struct cxl_event_common {
99+
struct cxl_event_record_hdr hdr;
100+
__le64 phys_addr;
101+
} __packed;
102+
94103
union cxl_event {
95104
struct cxl_event_generic generic;
96105
struct cxl_event_gen_media gen_media;
97106
struct cxl_event_dram dram;
98107
struct cxl_event_mem_module mem_module;
108+
struct cxl_event_common common;
99109
} __packed;
100110

101111
/*

0 commit comments

Comments
 (0)