[PATCH v5 12/13] EDAC/ghes: Handle Memory Error Section 2 records
From: Pierre Gondois
Date: Mon Nov 30 2026 - 12:10:20 EST
Register a separate EDAC callback for GHES Memory Error Section 2
records. Map the error type, address, grain, location, DIMM and status
fields to an EDAC error report.
Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
---
drivers/edac/ghes_edac.c | 118 +++++++++++++++++++++++++++++++++++++++
1 file changed, 118 insertions(+)
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index 44111e40d9f5..d3544dc20649 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -391,6 +391,122 @@ static struct notifier_block ghes_edac_mem_err_nb = {
.priority = 0,
};
+static int print_mem_error2_other_detail(const struct cper_sec_mem_err2 *mem, char *msg,
+ const char *location, size_t len)
+{
+ u32 n;
+
+ if (!msg || !len)
+ return 0;
+
+ n = 0;
+
+ n += scnprintf(msg + n, len - n, "APEI location: %s ", location);
+
+ if (mem->validation_bits & CPER_MEM2_VALID_ERROR_STATUS) {
+ n += scnprintf(msg + n, len - n, "status(0x%016llx): ", mem->error_status);
+ n += scnprintf(msg + n, len - n, "%s ",
+ cper_mem_err_status_str(mem->error_status));
+ }
+ if (mem->validation_bits & CPER_MEM2_VALID_STATUS)
+ n += scnprintf(msg + n, len - n, "section_status:0x%02x ",
+ mem->status);
+
+ msg[n] = '\0';
+
+ return n;
+}
+
+static int ghes_edac_report_mem_error2(struct notifier_block *nb,
+ unsigned long val, void *data)
+{
+ struct cper_sec_mem_err2 *mem_err = data;
+ struct edac_raw_error_desc *e;
+ struct mem_ctl_info *mci;
+ struct ghes_pvt *pvt;
+ size_t len;
+ char *p;
+
+ /*
+ * We can do the locking below because GHES defers error processing
+ * from NMI to IRQ context. Whenever that changes, we'd at least
+ * know.
+ */
+ if (WARN_ON_ONCE(in_nmi()))
+ return NOTIFY_OK;
+
+ guard(spinlock_irqsave)(&ghes_lock);
+
+ pvt = ghes_pvt;
+ if (!pvt)
+ return NOTIFY_OK;
+
+ mci = pvt->mci;
+ e = &mci->error_desc;
+ ghes_edac_init_error_desc(e, val, pvt->msg, pvt->other_detail);
+
+ edac_dbg(1, "error validation_bits: 0x%08llx\n",
+ (long long)mem_err->validation_bits);
+
+ /* Error type, mapped on e->msg */
+ if (mem_err->validation_bits & CPER_MEM2_VALID_ERROR_TYPE) {
+ u8 etype = mem_err->error_type;
+
+ p = pvt->msg;
+ p += snprintf(p, sizeof(pvt->msg), "%s", cper_mem_err_type_str(etype));
+ } else {
+ strscpy(pvt->msg, "unknown error");
+ }
+
+ /* Error address */
+ if (mem_err->validation_bits & CPER_MEM2_VALID_PA) {
+ e->page_frame_number = PHYS_PFN(mem_err->physical_addr);
+ e->offset_in_page = offset_in_page(mem_err->physical_addr);
+ }
+
+ /* Error grain */
+ if (mem_err->validation_bits & CPER_MEM2_VALID_PA_MASK)
+ e->grain = ~mem_err->physical_addr_mask + 1;
+
+ /* Memory error location, mapped on e->location */
+ len = sizeof(e->location);
+ p = e->location;
+ p += cper_mem_err2_location(mem_err, p, len);
+
+ if (mem_err->validation_bits & CPER_MEM2_VALID_MODULE_HANDLE) {
+ struct dimm_info *dimm = NULL;
+
+ p += cper_dimm_err2_location(mem_err, p, len - (p - e->location));
+ if (mem_err->mem_dev_handle <= U16_MAX) {
+ dimm = find_dimm_by_handle(mci, mem_err->mem_dev_handle);
+ if (dimm) {
+ e->top_layer = dimm->idx;
+ strscpy(e->label, dimm->label);
+ }
+ }
+ }
+ if (p > e->location && p[-1] == ' ')
+ *(p - 1) = '\0';
+
+ if (!*e->label)
+ strscpy(e->label, "unknown memory");
+
+ /* All other fields are mapped on e->other_detail */
+ p = pvt->other_detail;
+ p += print_mem_error2_other_detail(mem_err, p, e->location, sizeof(pvt->other_detail));
+ if (p > pvt->other_detail && p[-1] == ' ')
+ *(p - 1) = '\0';
+
+ edac_raw_mc_handle_error(e);
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block ghes_edac_mem_err2_nb = {
+ .notifier_call = ghes_edac_report_mem_error2,
+ .priority = 0,
+};
+
static int ghes_edac_register(struct device *dev)
{
bool fake = false;
@@ -495,6 +611,7 @@ static int ghes_edac_register(struct device *dev)
spin_unlock_irqrestore(&ghes_lock, flags);
ghes_register_report_chain(&ghes_edac_mem_err_nb);
+ ghes_register_report_mem2_chain(&ghes_edac_mem_err2_nb);
/* only set on success */
refcount_set(&ghes_refcount, 1);
@@ -538,6 +655,7 @@ static void ghes_edac_unregister(struct ghes *ghes)
if (mci)
edac_mc_free(mci);
+ ghes_unregister_report_mem2_chain(&ghes_edac_mem_err2_nb);
ghes_unregister_report_chain(&ghes_edac_mem_err_nb);
unlock:
--
2.43.0