Skip to contentSkip to conversation

cxl/events: Use a common struct for DRAM and General Media events

PATCH Superseded Fabio M. De Francesco 4 participants 6 messages May 16, 2024 – May 17, 2024 CXL

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cxl/events: Use a common struct for DRAM and General Media events

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and cxl_dram events")

---

Changes for v2:
- Extend the commit message (Alison);
- Add a "Fixes" tag (Alison, thanks).

 drivers/cxl/core/mbox.c      |  6 ++--
 drivers/cxl/core/trace.h     |  4 +--
 include/linux/cxl-event.h    | 70 +++++++++++++++---------------------
 tools/testing/cxl/test/mem.c |  4 +--
 4 files changed, 36 insertions(+), 48 deletions(-)
drivers/cxl/core/mbox.c +3 -3
index 2626f3fff201..ad4d7b0f7f4d 100644
@@ -875,16 +875,16 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 		guard(rwsem_read)(&cxl_region_rwsem);
 		guard(rwsem_read)(&cxl_dpa_rwsem);
 
-		dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
+		dpa = le64_to_cpu(evt->media_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);
+						&evt->media_general);
 		else if (event_type == CXL_CPER_EVENT_DRAM)
-			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
+			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->media_dram);
 	}
 }
 EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
drivers/cxl/core/trace.h +2 -2
index 07a0394b1d99..2c7293761bb2 100644
@@ -316,7 +316,7 @@ TRACE_EVENT(cxl_generic_event,
 TRACE_EVENT(cxl_general_media,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_gen_media *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
@@ -413,7 +413,7 @@ TRACE_EVENT(cxl_general_media,
 TRACE_EVENT(cxl_dram,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_dram *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
include/linux/cxl-event.h +29 -41

91 lines not on this page · raw message

tools/testing/cxl/test/mem.c +2 -2
index 6584443144de..0a8fd145c391 100644
@@ -378,7 +378,7 @@ struct cxl_event_record_raw hardware_replace = {
 
 struct cxl_test_gen_media {
 	uuid_t id;
-	struct cxl_event_gen_media rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_gen_media gen_media = {
@@ -402,7 +402,7 @@ struct cxl_test_gen_media gen_media = {
 
 struct cxl_test_dram {
 	uuid_t id;
-	struct cxl_event_dram rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_dram dram = {
Signature · 1 line
2.45.0
#1 lore raw
Quoted 10 lines · On Thu, 16 May 2024 12:19:53 +0200 "Fabio M. De Francesco"…

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and cxl_dram events")

---

Packing question inline.

Quoted 100 lines

Changes for v2:
- Extend the commit message (Alison);
- Add a "Fixes" tag (Alison, thanks).

 drivers/cxl/core/mbox.c      |  6 ++--
 drivers/cxl/core/trace.h     |  4 +--
 include/linux/cxl-event.h    | 70 +++++++++++++++---------------------
 tools/testing/cxl/test/mem.c |  4 +--
 4 files changed, 36 insertions(+), 48 deletions(-)
drivers/cxl/core/mbox.c +3 -3
index 2626f3fff201..ad4d7b0f7f4d 100644
@@ -875,16 +875,16 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 		guard(rwsem_read)(&cxl_region_rwsem);
 		guard(rwsem_read)(&cxl_dpa_rwsem);
 
-		dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
+		dpa = le64_to_cpu(evt->media_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);
+						&evt->media_general);
 		else if (event_type == CXL_CPER_EVENT_DRAM)
-			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
+			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->media_dram);
 	}
 }
 EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
drivers/cxl/core/trace.h +2 -2
index 07a0394b1d99..2c7293761bb2 100644
@@ -316,7 +316,7 @@ TRACE_EVENT(cxl_generic_event,
 TRACE_EVENT(cxl_general_media,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_gen_media *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
@@ -413,7 +413,7 @@ TRACE_EVENT(cxl_general_media,
 TRACE_EVENT(cxl_dram,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_dram *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
include/linux/cxl-event.h +1 -28
index 60b25020281f..e417556cc120 100644
@@ -32,41 +32,38 @@ struct cxl_event_generic {
  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
  */
 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE	0x10
-struct cxl_event_gen_media {
-	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	u8 device[3];
-	u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
-	u8 reserved[46];
-} __packed;
-
 /*
  * DRAM Event Record - DER
  * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
  */
 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE	0x20
-struct cxl_event_dram {
+struct cxl_event_media {
 	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	u8 nibble_mask[3];
-	u8 bank_group;
-	u8 bank;
-	u8 row[3];
-	u8 column[2];
-	u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];

include/linux/cxl-event.h struct cxl_event_generic { · line 50

Quoted 10 lines
include/linux/cxl-event.h +9 -1
-	u8 reserved[0x17];
+	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;
+	);

Does the struct that is created end up __packed?
Also, why is tagged useful here?

Quoted 66 lines
include/linux/cxl-event.h +19 -12
+	union {
+		struct_group(general,
+			u8 device[3];
+			u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
+			u8 gen_reserved[46];
+		);
+		struct_group(dram,
+			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;
 
 /*
@@ -95,21 +92,12 @@ 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_media media_general;
+	struct cxl_event_media media_dram;
 	struct cxl_event_mem_module mem_module;
-	struct cxl_event_common common;
+	struct cxl_event_media media_common;
 } __packed;
 
 /*
tools/testing/cxl/test/mem.c +2 -2
index 6584443144de..0a8fd145c391 100644
@@ -378,7 +378,7 @@ struct cxl_event_record_raw hardware_replace = {
 
 struct cxl_test_gen_media {
 	uuid_t id;
-	struct cxl_event_gen_media rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_gen_media gen_media = {
@@ -402,7 +402,7 @@ struct cxl_test_gen_media gen_media = {
 
 struct cxl_test_dram {
 	uuid_t id;
-	struct cxl_event_dram rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_dram dram = {
#2 lore raw

Jonathan,

Thanks for your comments.

Quoted 40 lines · On Thursday, May 16, 2024 6:33:19 PM GMT+2 Jonathan Cameron wrote:

On Thu, 16 May 2024 12:19:53 +0200

Quoted 10 lines · Fabio M. De Francesco

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and

cxl_dram events") Signed-off-by: Fabio M. De Francesco <[email protected]> ---

Packing question inline.

Quoted 24 lines

[...]

include/linux/cxl-event.h +4 -15
-struct cxl_event_dram {
+struct cxl_event_media {
 
 	struct cxl_event_record_hdr hdr;
 
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	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 reserved[0x17];
+	struct_group_tagged(cxl_event_media_hdr, media_hdr,
+		__le64 phys_addr;
+		u8 descriptor;
Quoted 8 lines

include/linux/cxl-event.h struct cxl_event_generic { · line 50

Quoted 6 lines
include/linux/cxl-event.h +6 -0
+		u8 type;
+		u8 transaction_type;
+		u8 validity_flags[2];
+		u8 channel;
+		u8 rank;
+	);

Does the struct that is created end up __packed?

No, I should have noticed it.

Quoted 1 line

Also, why is tagged useful here?

It is not useful. I'll rework it not tagged.

Again thanks,

Fabio

Quoted 4 lines

include/linux/cxl-event.h struct cxl_event_generic {

Quoted 4 lines
include/linux/cxl-event.h +4 -0
+	union {
+		struct_group(general,
+			u8 device[3];
+			u8 

component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];

Quoted 9 lines

include/linux/cxl-event.h struct cxl_event_generic {

Quoted 9 lines
include/linux/cxl-event.h +9 -0
+			u8 gen_reserved[46];
+		);
+		struct_group(dram,
+			u8 nibble_mask[3];
+			u8 bank_group;
+			u8 bank;
+			u8 row[3];
+			u8 column[2];
+			u8 

correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];

Quoted 6 lines
Quoted 6 lines
include/linux/cxl-event.h +3 -0
+			u8 dram_reserved[0x17];
+		);
+	};
 
 } __packed;
#3 lore raw
In reply to Fabio M. De Francesco
Quoted 15 lines · Fabio M. De Francesco

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and cxl_dram events")

---

Changes for v2:
- Extend the commit message (Alison);
- Add a "Fixes" tag (Alison, thanks).

Quoted 5 lines
 drivers/cxl/core/mbox.c      |  6 ++--
 drivers/cxl/core/trace.h     |  4 +--
 include/linux/cxl-event.h    | 70 +++++++++++++++---------------------
 tools/testing/cxl/test/mem.c |  4 +--
 4 files changed, 36 insertions(+), 48 deletions(-)

Still not convinced this is worth the churn.
Ira

Quoted 169 lines
drivers/cxl/core/mbox.c +3 -3
index 2626f3fff201..ad4d7b0f7f4d 100644
@@ -875,16 +875,16 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 		guard(rwsem_read)(&cxl_region_rwsem);
 		guard(rwsem_read)(&cxl_dpa_rwsem);
 
-		dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
+		dpa = le64_to_cpu(evt->media_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);
+						&evt->media_general);
 		else if (event_type == CXL_CPER_EVENT_DRAM)
-			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
+			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->media_dram);
 	}
 }
 EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
drivers/cxl/core/trace.h +2 -2
index 07a0394b1d99..2c7293761bb2 100644
@@ -316,7 +316,7 @@ TRACE_EVENT(cxl_generic_event,
 TRACE_EVENT(cxl_general_media,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_gen_media *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
@@ -413,7 +413,7 @@ TRACE_EVENT(cxl_general_media,
 TRACE_EVENT(cxl_dram,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_dram *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
include/linux/cxl-event.h +29 -41
index 60b25020281f..e417556cc120 100644
@@ -32,41 +32,38 @@ struct cxl_event_generic {
  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
  */
 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE	0x10
-struct cxl_event_gen_media {
-	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	u8 device[3];
-	u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
-	u8 reserved[46];
-} __packed;
-
 /*
  * DRAM Event Record - DER
  * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
  */
 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE	0x20
-struct cxl_event_dram {
+struct cxl_event_media {
 	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	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 reserved[0x17];
+	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(dram,
+			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;
 
 /*
@@ -95,21 +92,12 @@ 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_media media_general;
+	struct cxl_event_media media_dram;
 	struct cxl_event_mem_module mem_module;
-	struct cxl_event_common common;
+	struct cxl_event_media media_common;
 } __packed;
 
 /*
tools/testing/cxl/test/mem.c +2 -2
index 6584443144de..0a8fd145c391 100644
@@ -378,7 +378,7 @@ struct cxl_event_record_raw hardware_replace = {
 
 struct cxl_test_gen_media {
 	uuid_t id;
-	struct cxl_event_gen_media rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_gen_media gen_media = {
@@ -402,7 +402,7 @@ struct cxl_test_gen_media gen_media = {
 
 struct cxl_test_dram {
 	uuid_t id;
-	struct cxl_event_dram rec;
+	struct cxl_event_media rec;
 } __packed;
 
 struct cxl_test_dram dram = {
Signature · 1 line
2.45.0
#4 lore raw
In reply to Fabio M. De Francesco
Quoted 2 lines · Fabio M. De Francesco

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

I would say "unfortunate" rather than "poor".

Quoted 5 lines

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and cxl_dram events")

What is the fix? There is no user visible behavior changes that results from this cleanup, right?

Quoted 7 lines

---

Changes for v2:
- Extend the commit message (Alison);
- Add a "Fixes" tag (Alison, thanks).

Quoted 5 lines
 drivers/cxl/core/mbox.c      |  6 ++--
 drivers/cxl/core/trace.h     |  4 +--
 include/linux/cxl-event.h    | 70 +++++++++++++++---------------------
 tools/testing/cxl/test/mem.c |  4 +--
 4 files changed, 36 insertions(+), 48 deletions(-)

Oh, nice, net reduction in code I was not expecting.

drivers/cxl/core/mbox.c void cxl_event_trace_record(const struct cxl_memdev *cxlmd, · line 878

Quoted 11 lines
drivers/cxl/core/mbox.c +1 -1
index 2626f3fff201..ad4d7b0f7f4d 100644
@@ -875,16 +875,16 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
 		guard(rwsem_read)(&cxl_region_rwsem);
 		guard(rwsem_read)(&cxl_dpa_rwsem);
 
-		dpa = le64_to_cpu(evt->common.phys_addr) & CXL_DPA_MASK;
+		dpa = le64_to_cpu(evt->media_common.phys_addr) & CXL_DPA_MASK;

I was hoping at the end of this to get rid of the word "common" to avoid any more "common event record confusion".

Quoted 79 lines
drivers/cxl/core/mbox.c +2 -2
 		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);
+						&evt->media_general);
 		else if (event_type == CXL_CPER_EVENT_DRAM)
-			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->dram);
+			trace_cxl_dram(cxlmd, type, cxlr, hpa, &evt->media_dram);
 	}
 }
 EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
drivers/cxl/core/trace.h +2 -2
index 07a0394b1d99..2c7293761bb2 100644
@@ -316,7 +316,7 @@ TRACE_EVENT(cxl_generic_event,
 TRACE_EVENT(cxl_general_media,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_gen_media *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
@@ -413,7 +413,7 @@ TRACE_EVENT(cxl_general_media,
 TRACE_EVENT(cxl_dram,
 
 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
-		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_dram *rec),
+		 struct cxl_region *cxlr, u64 hpa, struct cxl_event_media *rec),
 
 	TP_ARGS(cxlmd, log, cxlr, hpa, rec),
 
include/linux/cxl-event.h +1 -28
index 60b25020281f..e417556cc120 100644
@@ -32,41 +32,38 @@ struct cxl_event_generic {
  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
  */
 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE	0x10
-struct cxl_event_gen_media {
-	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	u8 device[3];
-	u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
-	u8 reserved[46];
-} __packed;
-
 /*
  * DRAM Event Record - DER
  * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
  */
 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE	0x20
-struct cxl_event_dram {
+struct cxl_event_media {
 	struct cxl_event_record_hdr hdr;
-	__le64 phys_addr;
-	u8 descriptor;
-	u8 type;
-	u8 transaction_type;
-	u8 validity_flags[2];
-	u8 channel;
-	u8 rank;
-	u8 nibble_mask[3];
-	u8 bank_group;
-	u8 bank;
-	u8 row[3];
-	u8 column[2];
-	u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];

include/linux/cxl-event.h struct cxl_event_generic { · line 50

Quoted 10 lines
include/linux/cxl-event.h +9 -1
-	u8 reserved[0x17];
+	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;
+	);

Oh nice you went for the full 'struct_group_tagged' proposal. However, given that Jonathan is already asking questions about "__packed", lets do the simpler change, something like this, what do you think? This also preserves type-safety.

include/linux/cxl-event.h +12 -17
index 60b25020281f..f48b59943977 100644
@@ -33,14 +33,16 @@ struct cxl_event_generic {
  */
 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE 0x10
 struct cxl_event_gen_media {
-       struct cxl_event_record_hdr hdr;
-       __le64 phys_addr;
-       u8 descriptor;
-       u8 type;
-       u8 transaction_type;
-       u8 validity_flags[2];
-       u8 channel;
-       u8 rank;
+       struct cxl_event_media_hdr {
+               struct cxl_event_record_hdr hdr;
+               __le64 phys_addr;
+               u8 descriptor;
+               u8 type;
+               u8 transaction_type;
+               u8 validity_flags[2];
+               u8 channel;
+               u8 rank;
+       } hdr;
        u8 device[3];
        u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
        u8 reserved[46];
@@ -52,14 +54,7 @@ struct cxl_event_gen_media {
  */
 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE     0x20
 struct cxl_event_dram {
-       struct cxl_event_record_hdr hdr;
-       __le64 phys_addr;
-       u8 descriptor;
-       u8 type;
-       u8 transaction_type;
-       u8 validity_flags[2];
-       u8 channel;
-       u8 rank;
+       struct cxl_event_media_hdr hdr;
        u8 nibble_mask[3];
        u8 bank_group;
        u8 bank;
@@ -109,7 +104,7 @@ union cxl_event {
        struct cxl_event_gen_media gen_media;
        struct cxl_event_dram dram;
        struct cxl_event_mem_module mem_module;
-       struct cxl_event_common common;
+       struct cxl_event_media_hdr media_hdr;
 } __packed;
 
 /*
#5 lore raw
Quoted 6 lines · On Friday, May 17, 2024 2:43:33 AM GMT+2 Dan Williams wrote:
Quoted 2 lines · Fabio M. De Francesco

cxl_event_common was a poor naming choice and caused confusion with the existing Common Event Record.

I would say "unfortunate" rather than "poor".

Agreed.

Quoted 8 lines
Quoted 6 lines

Use cxl_event_media as a common structure to record information about DRAM and General Media events because it simplifies handling the two events.

Fixes 6aec00139d3a ("cxl/core: Add region info to cxl_general_media and

cxl_dram events")

What is the fix? There is no user visible behavior changes that results from this cleanup, right?

Right.

Quoted 25 lines
Quoted 8 lines

Signed-off-by: Fabio M. De Francesco
<[email protected]>
---

Changes for v2:
- Extend the commit message (Alison);
- Add a "Fixes" tag (Alison, thanks).

Quoted 5 lines
 drivers/cxl/core/mbox.c      |  6 ++--
 drivers/cxl/core/trace.h     |  4 +--
 include/linux/cxl-event.h    | 70 +++++++++++++++---------------------
 tools/testing/cxl/test/mem.c |  4 +--
 4 files changed, 36 insertions(+), 48 deletions(-)

Oh, nice, net reduction in code I was not expecting.

Quoted 9 lines
drivers/cxl/core/mbox.c +0 -0
index 2626f3fff201..ad4d7b0f7f4d 100644
@@ -875,16 +875,16 @@ void cxl_event_trace_record(const struct cxl_memdev
 *cxlmd,> 
 		guard(rwsem_read)(&cxl_region_rwsem);
 		guard(rwsem_read)(&cxl_dpa_rwsem);
 
Quoted 1 line

drivers/cxl/core/mbox.c void cxl_event_trace_record(const struct cxl_memdev · line 879

Quoted 1 line
drivers/cxl/core/mbox.c +0 -1
-		dpa = le64_to_cpu(evt->common.phys_addr) & 

CXL_DPA_MASK;

Quoted 1 line

drivers/cxl/core/mbox.c void cxl_event_trace_record(const struct cxl_memdev · line 879

Quoted 1 line
drivers/cxl/core/mbox.c +1 -0
+		dpa = le64_to_cpu(evt->media_common.phys_addr) & 

CXL_DPA_MASK;

Quoted 3 lines

I was hoping at the end of this to get rid of the word "common" to avoid any more "common event record confusion".

Right, still an unfortunate naming choice.

Quoted 5 lines
Quoted 1 line

[...]

Oh nice you went for the full 'struct_group_tagged' proposal. However, given that Jonathan is already asking questions about "__packed", lets do the simpler change, something like this, what do you think?

I think that these simpler changes are better.

Quoted 49 lines

This also preserves
type-safety.

include/linux/cxl-event.h +11 -16
index 60b25020281f..f48b59943977 100644
@@ -33,14 +33,16 @@ struct cxl_event_generic {
  */
 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE 0x10
 struct cxl_event_gen_media {
-       struct cxl_event_record_hdr hdr;
-       __le64 phys_addr;
-       u8 descriptor;
-       u8 type;
-       u8 transaction_type;
-       u8 validity_flags[2];
-       u8 channel;
-       u8 rank;
+       struct cxl_event_media_hdr {
+               struct cxl_event_record_hdr hdr;
+               __le64 phys_addr;
+               u8 descriptor;
+               u8 type;
+               u8 transaction_type;
+               u8 validity_flags[2];
+               u8 channel;
+               u8 rank;
+       } hdr;
        u8 device[3];
        u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
        u8 reserved[46];
@@ -52,14 +54,7 @@ struct cxl_event_gen_media {
  */
 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE     0x20
 struct cxl_event_dram {
-       struct cxl_event_record_hdr hdr;
-       __le64 phys_addr;
-       u8 descriptor;
-       u8 type;
-       u8 transaction_type;
-       u8 validity_flags[2];
-       u8 channel;
-       u8 rank;
+       struct cxl_event_media_hdr hdr;
        u8 nibble_mask[3];
        u8 bank_group;
        u8 bank;

include/linux/cxl-event.h union cxl_event { · line 110

Quoted 8 lines
include/linux/cxl-event.h +1 -1
@@ -109,7 +104,7 @@ union cxl_event {
        struct cxl_event_gen_media gen_media;
        struct cxl_event_dram dram;
        struct cxl_event_mem_module mem_module;
-       struct cxl_event_common common;
+       struct cxl_event_media_hdr media_hdr;
 } __packed;
 
 /*

I'll make v3 according to the suggestion showed above.

Thanks,

Fabio