[PATCH v2 3/6] cper: add helpers to handle Memory Error Section 2
From: Pierre Gondois
Date: Mon Oct 19 2026 - 16:49:21 EST
Add separate location and printing helpers for Memory Error
Section 2:
- cper_mem_err2_location()
- cper_dimm_err2_location()
- cper_print_mem2()
Similar functions/logic exists for Memory Error Section (1),
but require a compact version of the record. To avoid relying
and propagating a non-standard record format, the new functions
directly rely on struct cper_sec_mem_err2.
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
---
drivers/firmware/efi/cper.c | 109 ++++++++++++++++++++++++++++++++++++
include/linux/cper.h | 3 +
2 files changed, 112 insertions(+)
diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index 06b4fdb59917..42e324d5707c 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -445,6 +445,107 @@ static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
printk("%s%s\n", pfx, rcd_decode_str);
}
+int cper_mem_err2_location(const struct cper_sec_mem_err2 *mem, char *msg)
+{
+ u32 len, n;
+
+ if (!msg)
+ return 0;
+
+ n = 0;
+ len = CPER_REC_LEN;
+ if (mem->validation_bits & CPER_MEM2_VALID_NODE)
+ n += scnprintf(msg + n, len - n, "node:%d ", mem->node);
+ if (mem->validation_bits & CPER_MEM2_VALID_CARD)
+ n += scnprintf(msg + n, len - n, "card:%d ", mem->card);
+ if (mem->validation_bits & CPER_MEM2_VALID_MODULE)
+ n += scnprintf(msg + n, len - n, "module:%d ", mem->module);
+ if (mem->validation_bits & CPER_MEM2_VALID_RANK_NUMBER)
+ n += scnprintf(msg + n, len - n, "rank:%u ", mem->rank);
+ if (mem->validation_bits & CPER_MEM2_VALID_BANK)
+ n += scnprintf(msg + n, len - n, "bank:%d ", mem->bank);
+ if (mem->validation_bits & CPER_MEM2_VALID_BANK_GROUP)
+ n += scnprintf(msg + n, len - n, "bank_group:%d ",
+ mem->bank >> CPER_MEM_BANK_GROUP_SHIFT);
+ if (mem->validation_bits & CPER_MEM2_VALID_BANK_ADDRESS)
+ n += scnprintf(msg + n, len - n, "bank_address:%d ",
+ mem->bank & CPER_MEM_BANK_ADDRESS_MASK);
+ if (mem->validation_bits & CPER_MEM2_VALID_DEVICE)
+ n += scnprintf(msg + n, len - n, "device:%u ", mem->device);
+ if (mem->validation_bits & CPER_MEM2_VALID_ROW)
+ n += scnprintf(msg + n, len - n, "row:%u ", mem->row);
+ if (mem->validation_bits & CPER_MEM2_VALID_COLUMN)
+ n += scnprintf(msg + n, len - n, "column:%u ", mem->column);
+ if (mem->validation_bits & CPER_MEM2_VALID_BIT_POSITION)
+ n += scnprintf(msg + n, len - n, "bit_position:%u ",
+ mem->bit_pos);
+ if (mem->validation_bits & CPER_MEM2_VALID_REQUESTOR_ID)
+ n += scnprintf(msg + n, len - n, "requestor_id:0x%016llx ",
+ mem->requestor_id);
+ if (mem->validation_bits & CPER_MEM2_VALID_RESPONDER_ID)
+ n += scnprintf(msg + n, len - n, "responder_id:0x%016llx ",
+ mem->responder_id);
+ if (mem->validation_bits & CPER_MEM2_VALID_TARGET_ID)
+ n += scnprintf(msg + n, len - n, "target_id:0x%016llx ",
+ mem->target_id);
+ if (mem->validation_bits & CPER_MEM2_VALID_CHIP_ID)
+ n += scnprintf(msg + n, len - n, "chip_id:%d ",
+ mem->chip_id);
+
+ return n;
+}
+EXPORT_SYMBOL_GPL(cper_mem_err2_location);
+
+int cper_dimm_err2_location(const struct cper_sec_mem_err2 *mem, char *msg)
+{
+ u32 len, n;
+ const char *bank = NULL, *device = NULL;
+
+ if (!msg || !(mem->validation_bits & CPER_MEM2_VALID_MODULE_HANDLE))
+ return 0;
+
+ /* SMBIOS handles are 16 bits; never truncate a Section 2 handle. */
+ if (mem->mem_dev_handle <= U16_MAX)
+ dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
+ else
+ pr_warn(FW_WARN "Memory Error Section 2 module handle 0x%x exceeds SMBIOS range\n",
+ mem->mem_dev_handle);
+
+ len = CPER_REC_LEN;
+ if (bank && device)
+ n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
+ else
+ n = snprintf(msg, len,
+ "DIMM location: not present. DMI handle: 0x%.8x ",
+ mem->mem_dev_handle);
+
+ return n;
+}
+EXPORT_SYMBOL_GPL(cper_dimm_err2_location);
+
+static void cper_print_mem2(const char *pfx, const struct cper_sec_mem_err2 *mem)
+{
+ char rcd_decode_str[CPER_REC_LEN];
+
+ if (mem->validation_bits & CPER_MEM2_VALID_ERROR_STATUS)
+ printk("%serror_status: %s (0x%016llx)\n", pfx,
+ cper_mem_err_status_str(mem->error_status), mem->error_status);
+ if (mem->validation_bits & CPER_MEM2_VALID_PA)
+ printk("%sphysical_address: 0x%016llx\n", pfx, mem->physical_addr);
+ if (mem->validation_bits & CPER_MEM2_VALID_PA_MASK)
+ printk("%sphysical_address_mask: 0x%016llx\n", pfx,
+ mem->physical_addr_mask);
+ if (cper_mem_err2_location(mem, rcd_decode_str))
+ printk("%s%s\n", pfx, rcd_decode_str);
+ if (mem->validation_bits & CPER_MEM2_VALID_ERROR_TYPE)
+ printk("%serror_type: %u, %s\n", pfx, mem->error_type,
+ cper_mem_err_type_str(mem->error_type));
+ if (mem->validation_bits & CPER_MEM2_VALID_STATUS)
+ printk("%sstatus: 0x%02x\n", pfx, mem->status);
+ if (cper_dimm_err2_location(mem, rcd_decode_str))
+ printk("%s%s\n", pfx, rcd_decode_str);
+}
+
static const char * const pcie_port_type_strs[] = {
"PCIe end point",
"legacy PCI end point",
@@ -650,6 +751,14 @@ cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata
gdata->error_data_length);
else
goto err_section_too_small;
+ } else if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM2)) {
+ struct cper_sec_mem_err2 *mem_err = acpi_hest_get_payload(gdata);
+
+ printk("%ssection_type: memory error 2\n", newpfx);
+ if (gdata->error_data_length >= sizeof(*mem_err))
+ cper_print_mem2(newpfx, mem_err);
+ else
+ goto err_section_too_small;
} else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
struct cper_sec_pcie *pcie = acpi_hest_get_payload(gdata);
diff --git a/include/linux/cper.h b/include/linux/cper.h
index ed355b240685..a466cba4fd61 100644
--- a/include/linux/cper.h
+++ b/include/linux/cper.h
@@ -656,6 +656,9 @@ void cper_print_proc_ia(const char *pfx,
int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg);
int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg);
+int cper_mem_err2_location(const struct cper_sec_mem_err2 *mem, char *msg);
+int cper_dimm_err2_location(const struct cper_sec_mem_err2 *mem, char *msg);
+
struct acpi_hest_generic_status;
void cper_estatus_print(const char *pfx,
const struct acpi_hest_generic_status *estatus);
--
2.43.0