[PATCH v9] EDAC/loongson: Add CS4-7 timeout filter for cross-node access

From: Qunqin Zhao

Date: Mon Nov 30 2026 - 02:08:05 EST


From: Qunqin Zhao <zhaoqunqin@xxxxxxxxxxx>

On Loongson 3C6000 multi-node systems, when the EDAC driver running
on one node accesses the memory controller registers of another node,
the read operation may timeout and return random values. This causes
false CE error reports because the random values in CS0-3 (low 32 bits)
are misinterpreted as valid ECC error counts.

Co-developed-by: Wu sheng <wusheng@xxxxxxxxxxx>
Signed-off-by: Wu sheng <wusheng@xxxxxxxxxxx>
Co-developed-by: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
Signed-off-by: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
Signed-off-by: Qunqin Zhao <zhaoqunqin@xxxxxxxxxxx>
Reviewed-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
---
v9:
- Rebase onto latest edac-drivers-loongson
- Drop text explaining what the patch does in the commit message
- Fix SoB chains
- Reorder the variable declarations in probe()
v8:
- Fix Signed-off-by name format.
- edac_mc_printk --> edac_dbg.
- Remove a duplicate semicolon.
v4:
- int valid_cs_bits; -> u32 valid_cs_bits;
v2:
- Assign valid_cs_bits before calling read_ecc() in pvt_init() to
prevent using uninitialized data when establishing the baseline
error count
- Add bounds check for valid_cs_bits < 64 to guard against undefined
behavior when shifting a 64-bit value by 64 bits
- Rename device property valid_cs_bits -> valid-cs-bits to match
standard DT/ACPI _DSD hyphen convention

drivers/edac/loongson_edac.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index 05b95b712..c297c222b 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -29,6 +29,7 @@ struct loongson_pvt {
*/
int last_ce_count;
u32 mcs_per_node;
+ u32 valid_cs_bits;
};

static int read_ecc(struct mem_ctl_info *mci)
@@ -38,11 +39,21 @@ static int read_ecc(struct mem_ctl_info *mci)
int cs;

ecc = readq(pvt->ecc_base + ECC_CS_COUNT_REG);
- /* cs0 -- cs3 */
+ /* Discard the read value if any invalid bit is set to 1 */
+ if (pvt->valid_cs_bits < 64 && (ecc >> pvt->valid_cs_bits)) {
+ edac_dbg(2, "ECC read invalid, skip: 0x%llx\n", ecc);
+ return pvt->last_ce_count;
+ }
+
+ /* cs0 -- cs7 */
cs = ecc & 0xff;
cs += (ecc >> 8) & 0xff;
cs += (ecc >> 16) & 0xff;
cs += (ecc >> 24) & 0xff;
+ cs += (ecc >> 32) & 0xff;
+ cs += (ecc >> 40) & 0xff;
+ cs += (ecc >> 48) & 0xff;
+ cs += (ecc >> 56) & 0xff;

return cs;
}
@@ -112,22 +123,24 @@ static void dimm_config_init(struct mem_ctl_info *mci)
dimm->grain = 8;
}

-static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase, u32 mcs_per_node)
+static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase,
+ u32 mcs_per_node, u32 valid_cs_bits)
{
struct loongson_pvt *pvt = mci->pvt_info;

pvt->ecc_base = vbase;
- pvt->last_ce_count = read_ecc(mci);
pvt->mcs_per_node = mcs_per_node;
+ pvt->valid_cs_bits = valid_cs_bits;
+ pvt->last_ce_count = read_ecc(mci);
}

static int driver_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ u32 mcs_per_node, valid_cs_bits;
struct edac_mc_layer layers[2];
struct mem_ctl_info *mci;
void __iomem *vbase;
- u32 mcs_per_node;
int ret;

vbase = devm_platform_ioremap_resource(pdev, 0);
@@ -161,7 +174,10 @@ static int driver_probe(struct platform_device *pdev)
if (device_property_read_u32(dev, "mcs-per-node", &mcs_per_node) || !mcs_per_node)
mcs_per_node = 4;

- pvt_init(mci, vbase, mcs_per_node);
+ if (device_property_read_u32(dev, "valid-cs-bits", &valid_cs_bits))
+ valid_cs_bits = 32;
+
+ pvt_init(mci, vbase, mcs_per_node, valid_cs_bits);
dimm_config_init(mci);

ret = edac_mc_add_mc(mci);

base-commit: 82083da8b2c043972da075d7a5099e098f2991e3
--
2.47.2