Skip to contentSkip to conversation

Add DPA->HPA translation to dram & general_media events

PATCH In review [email protected] 2 participants 8 messages Apr 30, 2024 – May 8, 2024 CXL

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v6 cover Add DPA->HPA translation to dram & general_media events

From: Alison Schofield <[email protected]>

Changes in v6:
- No code changes
- Patch 1: Remove wrong comment about rasdaemon not being available (Jonathan)
- Patch 1: Add Fixes tag (Jonathan)
- Patch 3: Remove blank line in tag block (Jonathan)
- Patch 1,4: Add Reviewed-by tags (Jonathan, Ira)
- Link to v5: https://lore.kernel.org/[email protected]/

Begin Cover Letter:
Add HPA translations to CXL events: cxl_dram and cxl_general_media

Patch 1:
The DPA mask fix up patch must precede or be part of this set. It fixes the issue where upper 32 bits of DPA are truncated.

Patches 2 & 3:
Before adding the new support, do some housekeeping and move related helpers to the region driver because there is no looking up region related info without CONFIG_CXL_REGION.

Patch 4:
The new functionality is introduced - cxl_dram & cxl_general_media events. Lookup and log the DPA->HPA translation along with the region name and region uuid.

Alison Schofield (4):
cxl/trace: Correct DPA field masks for general_media & dram events cxl/region: Move cxl_dpa_to_region() work to the region driver cxl/region: Move cxl_trace_hpa() work to the region driver cxl/core: Add region info to cxl_general_media and cxl_dram events

 drivers/cxl/core/core.h   |  14 ++++
 drivers/cxl/core/mbox.c   |  36 ++++++++--
 drivers/cxl/core/memdev.c |  44 -------------
 drivers/cxl/core/region.c | 135 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/core/trace.c  |  91 -------------------------
 drivers/cxl/core/trace.h  |  50 ++++++++++----
 include/linux/cxl-event.h |  10 +++
 7 files changed, 226 insertions(+), 154 deletions(-)

base-commit: 4cece764965020c22cff7665b18a012006359095

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v6 1/4 cxl/trace: Correct DPA field masks for general_media & dram events

From: Alison Schofield <[email protected]>

The length of Physical Address in General Media and DRAM event records is 64-bit, so the field mask for extracting the DPA should be 64-bit also, otherwise the trace event reports DPA's with the upper 32 bits of a DPA address masked off. If users do DPA-to-HPA translations this could lead to incorrect page retirement decisions.

Use GENMASK_ULL() for CXL_DPA_MASK to get all the DPA address bits.

Tidy up CXL_DPA_FLAGS_MASK by using GENMASK() to only mask the exact flag bits.

These bits are defined as part of the event record physical address descriptions of General Media and DRAM events in CXL Spec 3.1 Section 8.2.9.2 Events.

Fixes d54a531a430b ("cxl/mem: Trace General Media Event Record")
---
 drivers/cxl/core/trace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/trace.h +2 -2
index e5f13260fc52..7c5cd069f10c 100644
@@ -253,8 +253,8 @@ TRACE_EVENT(cxl_generic_event,
  * DRAM Event Record
  * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
  */
-#define CXL_DPA_FLAGS_MASK			0x3F
-#define CXL_DPA_MASK				(~CXL_DPA_FLAGS_MASK)
+#define CXL_DPA_FLAGS_MASK			GENMASK(1, 0)
+#define CXL_DPA_MASK				GENMASK_ULL(63, 6)
 
 #define CXL_DPA_VOLATILE			BIT(0)
 #define CXL_DPA_NOT_REPAIRABLE			BIT(1)
Signature · 1 line
2.37.3
author maintainer
#2 lore raw

PATCH v6 2/4 cxl/region: Move cxl_dpa_to_region() work to the region driver

In reply to [email protected]

From: Alison Schofield <[email protected]>

This helper belongs in the region driver as it is only useful with CONFIG_CXL_REGION. Add a stub in core.h for when the region driver is not built.

---
 drivers/cxl/core/core.h   |  7 +++++++
 drivers/cxl/core/memdev.c | 44 ---------------------------------------
 drivers/cxl/core/region.c | 44 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 44 deletions(-)
drivers/cxl/core/core.h +7 -0
index bc5a95665aa0..87008505f8a9 100644
@@ -27,7 +27,14 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
 int cxl_region_init(void);
 void cxl_region_exit(void);
 int cxl_get_poison_by_endpoint(struct cxl_port *port);
+struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa);
+
 #else
+static inline
+struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
+{
+	return NULL;
+}
 static inline int cxl_get_poison_by_endpoint(struct cxl_port *port)
 {
 	return 0;
drivers/cxl/core/memdev.c +0 -44

50 lines not on this page · raw message

drivers/cxl/core/region.c +44 -0

50 lines not on this page · raw message

Signature · 1 line
2.37.3
author maintainer
#3 lore raw

PATCH v6 3/4 cxl/region: Move cxl_trace_hpa() work to the region driver

In reply to [email protected]

From: Alison Schofield <[email protected]>

This work belongs in the region driver as it is only useful with CONFIG_CXL_REGION. Add a stub in core.h for when the region driver is not built.

---
 drivers/cxl/core/core.h   |  7 +++
 drivers/cxl/core/region.c | 91 +++++++++++++++++++++++++++++++++++++++
 drivers/cxl/core/trace.c  | 91 ---------------------------------------
 drivers/cxl/core/trace.h  |  2 -
 4 files changed, 98 insertions(+), 93 deletions(-)
drivers/cxl/core/core.h +7 -0
index 87008505f8a9..625394486459 100644
@@ -28,8 +28,15 @@ int cxl_region_init(void);
 void cxl_region_exit(void);
 int cxl_get_poison_by_endpoint(struct cxl_port *port);
 struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa);
+u64 cxl_trace_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
+		  u64 dpa);
 
 #else
+static inline u64
+cxl_trace_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa)
+{
+	return ULLONG_MAX;
+}
 static inline
 struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
 {
drivers/cxl/core/region.c +91 -0

97 lines not on this page · raw message

drivers/cxl/core/trace.c +0 -91

94 lines not on this page · raw message

drivers/cxl/core/trace.h +0 -2
index 7c5cd069f10c..e303e618aa05 100644
@@ -642,8 +642,6 @@ 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 *cxlr,
Signature · 1 line
2.37.3
author maintainer
#4 lore raw

PATCH v6 4/4 cxl/core: Add region info to cxl_general_media and cxl_dram events

In reply to [email protected]

From: Alison Schofield <[email protected]>

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.

---
 drivers/cxl/core/mbox.c   | 36 ++++++++++++++++++++++++++------
 drivers/cxl/core/trace.h  | 44 +++++++++++++++++++++++++++++++--------
 include/linux/cxl-event.h | 10 +++++++++
 3 files changed, 75 insertions(+), 15 deletions(-)
drivers/cxl/core/mbox.c +30 -6
index 9adda4795eb7..df0fc2a4570f 100644
@@ -842,14 +842,38 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 			    enum cxl_event_type event_type,
 			    const uuid_t *uuid, union cxl_event *evt)
 {
-	if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
-		trace_cxl_general_media(cxlmd, type, &evt->gen_media);
-	else if (event_type == CXL_CPER_EVENT_DRAM)
-		trace_cxl_dram(cxlmd, type, &evt->dram);
-	else if (event_type == CXL_CPER_EVENT_MEM_MODULE)
+	if (event_type == CXL_CPER_EVENT_MEM_MODULE) {
 		trace_cxl_memory_module(cxlmd, type, &evt->mem_module);
-	else
+		return;
+	}
+	if (event_type == CXL_CPER_EVENT_GENERIC) {
 		trace_cxl_generic_event(cxlmd, type, uuid, &evt->generic);
+		return;
+	}
+
+	if (trace_cxl_general_media_enabled() || trace_cxl_dram_enabled()) {
+		u64 dpa, hpa = ULLONG_MAX;
+		struct cxl_region *cxlr;
+
+		/*
+		 * These trace points are annotated with HPA and region
+		 * translations. Take topology mutation locks and lookup
+		 * { HPA, REGION } from { DPA, MEMDEV } in the event record.
+		 */
+		guard(rwsem_read)(&cxl_region_rwsem);
+		guard(rwsem_read)(&cxl_dpa_rwsem);
+
+		dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
+		cxlr = cxl_dpa_to_region(cxlmd, dpa);
+		if (cxlr)
+			hpa = cxl_trace_hpa(cxlr, cxlmd, dpa);
+
+		if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
+			trace_cxl_general_media(cxlmd, type, cxlr, hpa,
+						&evt->gen_media);
+		else if (event_type == CXL_CPER_EVENT_DRAM)
+			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
+	}
 }
 EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
 
drivers/cxl/core/trace.h +35 -9

110 lines not on this page · raw message

include/linux/cxl-event.h +10 -0
index 03fa6d50d46f..5342755777cc 100644
@@ -91,11 +91,21 @@ struct cxl_event_mem_module {
 	u8 reserved[0x3d];
 } __packed;
 
+/*
+ * General Media or DRAM Event Common Fields
+ * - provides common access to phys_addr
+ */
+struct cxl_event_common {
+	struct cxl_event_record_hdr hdr;
+	__le64 phys_addr;
+} __packed;
+
 union cxl_event {
 	struct cxl_event_generic generic;
 	struct cxl_event_gen_media gen_media;
 	struct cxl_event_dram dram;
 	struct cxl_event_mem_module mem_module;
+	struct cxl_event_common common;
 } __packed;
 
 /*
Signature · 1 line
2.37.3
#5 lore raw

Re: [PATCH v6 4/4] cxl/core: Add region info to cxl_general_media and cxl_dram events

Quoted 23 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

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.

[..]

Quoted 13 lines
include/linux/cxl-event.h +5 -0
index 03fa6d50d46f..5342755777cc 100644
@@ -91,11 +91,21 @@ struct cxl_event_mem_module {
 	u8 reserved[0x3d];
 } __packed;
 
+/*
+ * General Media or DRAM Event Common Fields
+ * - provides common access to phys_addr
+ */
+struct cxl_event_common {

include/linux/cxl-event.h struct cxl_event_mem_module { · line 108

Quoted 10 lines
include/linux/cxl-event.h +5 -0
+	struct cxl_event_record_hdr hdr;
+	__le64 phys_addr;
+} __packed;
+
 union cxl_event {
 	struct cxl_event_generic generic;
 	struct cxl_event_gen_media gen_media;
 	struct cxl_event_dram dram;
 	struct cxl_event_mem_module mem_module;
+	struct cxl_event_common common;

I think we should rename this. As I was doing one last once-over my brain went "wait, there's no physical address in the Common Event Record".

So at a minimum call this "media_hdr" to match the style of cxl_event_record_hdr.

Now I say "minimum" because 'struct cxl_event_gen_media' and 'struct cxl_event_dram' should be including that struct in their definition to make it impossible that they have different definitions. I.e. I am not a fan of creating a new 'struct cxl_event_media_hdr' that is only consumed by 'union cxl_event'.

The "maximum" would be to combine these definitions into one common flexible format to maximize shared definitions, something like the below, but the thrash it would cause is probably on the same order as just adding a 'struct cxl_event_media_hdr media_hdr' member to existing 'struct cxl_event_gen_media' and 'struct cxl_event_dram', fixup all the users and call it a day,

struct cxl_event_media {
        struct cxl_event_record_hdr hdr;
        struct_group_tagged(cxl_event_media_hdr, media_hdr,
                __le64 phys_addr,
                u8 descriptor,
                u8 type,
                u8 transaction_type,
                u8 validity_flags[2],
                u8 channel,
                u8 rank,
        };
        union { 
                struct_group(general,
                        u8 device[3],
                        u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE],
                        u8 gen_reserved[46],
                );
                struct_group(media,
                        u8 nibble_mask[3],
                        u8 bank_group,
                        u8 bank,
                        u8 row[3],
                        u8 column[2],
                        u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE],
                        u8 dram_reserved[0x17],
                );
        };
} __packed;
#6 lore raw

Re: [PATCH v6 4/4] cxl/core: Add region info to cxl_general_media and cxl_dram events

Dan Williams wrote:
[..]

Quoted 17 lines

The "maximum" would be to combine these definitions into one common flexible format to maximize shared definitions, something like the below, but the thrash it would cause is probably on the same order as just adding a 'struct cxl_event_media_hdr media_hdr' member to existing 'struct cxl_event_gen_media' and 'struct cxl_event_dram', fixup all the users and call it a day,

struct cxl_event_media {
        struct cxl_event_record_hdr hdr;
        struct_group_tagged(cxl_event_media_hdr, media_hdr,
                __le64 phys_addr,
                u8 descriptor,
                u8 type,
                u8 transaction_type,
                u8 validity_flags[2],
                u8 channel,
                u8 rank,
Quoted 8 lines
        };
        union { 
                struct_group(general,
                        u8 device[3],
                        u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE],
                        u8 gen_reserved[46],
                );
                struct_group(media,

...should be "dram", but you get the idea.

Quoted 10 lines
                        u8 nibble_mask[3],
                        u8 bank_group,
                        u8 bank,
                        u8 row[3],
                        u8 column[2],
                        u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE],
                        u8 dram_reserved[0x17],
                );
        };
} __packed;
author maintainer
#7 lore raw

Re: [PATCH v6 4/4] cxl/core: Add region info to cxl_general_media and cxl_dram events

In reply to Dan Williams
Quoted 62 lines · Dan Williams
Quoted 23 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

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.

[..]

Quoted 13 lines
include/linux/cxl-event.h +5 -0
index 03fa6d50d46f..5342755777cc 100644
@@ -91,11 +91,21 @@ struct cxl_event_mem_module {
 	u8 reserved[0x3d];
 } __packed;
 
+/*
+ * General Media or DRAM Event Common Fields
+ * - provides common access to phys_addr
+ */
+struct cxl_event_common {

include/linux/cxl-event.h struct cxl_event_mem_module { · line 108

Quoted 10 lines
include/linux/cxl-event.h +5 -0
+	struct cxl_event_record_hdr hdr;
+	__le64 phys_addr;
+} __packed;
+
 union cxl_event {
 	struct cxl_event_generic generic;
 	struct cxl_event_gen_media gen_media;
 	struct cxl_event_dram dram;
 	struct cxl_event_mem_module mem_module;
+	struct cxl_event_common common;

I think we should rename this. As I was doing one last once-over my brain went "wait, there's no physical address in the Common Event Record".

So at a minimum call this "media_hdr" to match the style of cxl_event_record_hdr.

Now I say "minimum" because 'struct cxl_event_gen_media' and 'struct cxl_event_dram' should be including that struct in their definition to make it impossible that they have different definitions. I.e. I am not a fan of creating a new 'struct cxl_event_media_hdr' that is only consumed by 'union cxl_event'.

Quoted 6 lines

The "maximum" would be to combine these definitions into one common flexible format to maximize shared definitions, something like the below, but the thrash it would cause is probably on the same order as just adding a 'struct cxl_event_media_hdr media_hdr' member to existing 'struct cxl_event_gen_media' and 'struct cxl_event_dram', fixup all the users and call it a day,

I've added this to my queue to fixup.
Thanks for the review.

-- Alison

Quoted 29 lines
struct cxl_event_media {
        struct cxl_event_record_hdr hdr;
        struct_group_tagged(cxl_event_media_hdr, media_hdr,
                __le64 phys_addr,
                u8 descriptor,
                u8 type,
                u8 transaction_type,
                u8 validity_flags[2],
                u8 channel,
                u8 rank,
        };
        union { 
                struct_group(general,
                        u8 device[3],
                        u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE],
                        u8 gen_reserved[46],
                );
                struct_group(media,
                        u8 nibble_mask[3],
                        u8 bank_group,
                        u8 bank,
                        u8 row[3],
                        u8 column[2],
                        u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE],
                        u8 dram_reserved[0x17],
                );
        };
} __packed;