]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cxl/events: Add extra validity checks for corrected memory error count in General...
authorShiju Jose <shiju.jose@huawei.com>
Thu, 17 Jul 2025 10:18:15 +0000 (11:18 +0100)
committerDave Jiang <dave.jiang@intel.com>
Fri, 18 Jul 2025 15:19:56 +0000 (08:19 -0700)
According to the CXL Specification Revision 3.2, Section 8.2.10.2.1.1,
Table 8-57 (General Media Event Record), the Corrected Memory Error Count
field is valid under the following conditions:
1. The Threshold Event bit is set in the Memory Event Descriptor field,
and
2. The Corrected Memory Error Count must be greater than 0 for events
where the Advanced Programmable Threshold Counter has expired.

Additionally, if the Advanced Programmable Corrected Memory Error Counter
Expire bit in the Memory Event Type field is set, then the Threshold Event
bit in the Memory Event Descriptor field shall also be set.

Add validity checks for the above conditions while reporting the event to
the userspace.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Link: https://patch.msgid.link/20250717101817.2104-3-shiju.jose@huawei.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/mbox.c
drivers/cxl/core/trace.h

index 2689e6453c5addd065c30c2a3798a395aaad58a7..ba4a29afd3aa583b18a63a09c3336c409da1f212 100644 (file)
@@ -926,6 +926,15 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
                        if (cxl_store_rec_gen_media((struct cxl_memdev *)cxlmd, evt))
                                dev_dbg(&cxlmd->dev, "CXL store rec_gen_media failed\n");
 
+                       if (evt->gen_media.media_hdr.descriptor &
+                           CXL_GMER_EVT_DESC_THRESHOLD_EVENT)
+                               WARN_ON_ONCE((evt->gen_media.media_hdr.type &
+                                             CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE) &&
+                                            !get_unaligned_le24(evt->gen_media.cme_count));
+                       else
+                               WARN_ON_ONCE(evt->gen_media.media_hdr.type &
+                                            CXL_GMER_MEM_EVT_TYPE_AP_CME_COUNTER_EXPIRE);
+
                        trace_cxl_general_media(cxlmd, type, cxlr, hpa,
                                                hpa_alias, &evt->gen_media);
                } else if (event_type == CXL_CPER_EVENT_DRAM) {
index a77487a257b33f62d3b0ddd9a719c076ea2a2ceb..c38f94ca0ca1118e6ab1a9a96b314be0ad6ee63d 100644 (file)
@@ -506,7 +506,10 @@ TRACE_EVENT(cxl_general_media,
                        uuid_copy(&__entry->region_uuid, &uuid_null);
                }
                __entry->cme_threshold_ev_flags = rec->cme_threshold_ev_flags;
-               __entry->cme_count = get_unaligned_le24(rec->cme_count);
+               if (rec->media_hdr.descriptor & CXL_GMER_EVT_DESC_THRESHOLD_EVENT)
+                       __entry->cme_count = get_unaligned_le24(rec->cme_count);
+               else
+                       __entry->cme_count = 0;
        ),
 
        CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' " \