mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver
@ 2026-11-18  3:03 Qunqin Zhao
  2026-11-18  3:03 ` [PATCH v8 1/4] EDAC/loongson: Rename driver-local symbols Qunqin Zhao
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-18  3:03 UTC (permalink / raw)
  To: bp; +Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel

From: Qunqin Zhao <zhaoqunqin@loongson.cn>

This series contains four patches for the Loongson EDAC driver:

Patch 1: Rename driver-local symbols to remove the "edac_" prefix.

Patch 2: Encode node and MC info into mc_idx so that on multi-node
systems, sysfs entries uniquely identify each controller.

Patch 3: Get DIMM size from ACPI _DSM method instead of using hardcoded
values, enabling correct display of memory size in sysfs.

Patch 4: Add CS4-7 timeout filter for cross-node access on 3C6000
multi-node systems to prevent false CE error reports.

Changes in v8:

  Patch 4 "Add CS4-7 timeout filter for cross-node access":
  - Fix Signed-off-by name format.
  - edac_mc_printk --> edac_dbg(2). Drivers under drivers/edac generally
    use edac_dbg for debug prints. Then remove Reviewed-by tag from Huacai.
    Reserve level 1 for more important debug messages.
  - Remove a duplicate semicolon.

Changes in v7:

  Patch 2 "Encode node and MC info into mc_idx":
  - Encode the presence of the _DSD property into mc_idx. Then remove
    Reviewed-by tag from Huacai

Changes in v6:

  - Rename check(), probe() and remove() to loongson_check(),
    loongson_probe() and loongson_remove() respectively.

Changes in v5:

  - Add a new preparatory patch (Patch 1) that removes the "edac_" prefix
    from driver-local definitions: rename edac_check(), edac_probe() and
    edac_remove() to check(), probe() and remove(), respectively, and
    rename struct loongson_edac_pvt, loongson_edac_driver and
    loongson_edac_acpi_match to loongson_pvt, loongson_driver and
    loongson_acpi_match, respectively (Boris)
  - Reorder the variable declarations in probe() so that int ret is
    declared last, following the EDAC tree reverse-fir-tree convention
    (Boris)

Changes in v4:

  - int mcs_per_node; -> u32 mcs_per_node;
  - int valid_cs_bits; -> u32 valid_cs_bits;

Changes in v3:
  Patch 2 "Encode node and MC info into mc_idx":
  - Drop mc_idx_u32 temporary variable; pass &mci->mc_idx directly
  - Rename device property mc-per-node -> mcs-per-node

  Patch 3 "Get DIMM size from ACPI _DSM method":
  - Fix subject: get -> Get
  - No code changes

  Patch 4 "Add CS4-7 timeout filter for cross-node access":
  - No changes

Changes in v2:

  Patch 2 "Encode node and MC info into mc_idx":
  - Use char other_detail[64] = {0} and drop the else branch
  - Put snprintf() on one line
  - Initialize mc_idx_valid = true and drop the else branch
  - Validate mc-per-node firmware property is non-zero to prevent
    division by zero
  - Wrap pvt_init() function definition to satisfy 100-column limit

  Patch 3 "get DIMM size from ACPI _DSM method":
  - No changes; rebased on top of updated patch 2.

  Patch 4 "Add CS4-7 timeout filter for cross-node access":
  - 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


Qunqin Zhao (2):
  EDAC/loongson: Rename driver-local symbols
  EDAC/loongson: Add CS4-7 timeout filter for cross-node access

Wang Jinwei (2):
  EDAC/loongson: Encode node and MC info into mc_idx
  EDAC/loongson: Get DIMM size from ACPI _DSM method

 drivers/edac/loongson_edac.c | 112 +++++++++++++++++++++++++++--------
 1 file changed, 88 insertions(+), 24 deletions(-)


base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
-- 
2.47.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v8 1/4] EDAC/loongson: Rename driver-local symbols
  2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
@ 2026-11-18  3:03 ` Qunqin Zhao
  2026-11-18  3:03 ` [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx Qunqin Zhao
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-18  3:03 UTC (permalink / raw)
  To: bp
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel, Huacai Chen

From: Qunqin Zhao <zhaoqunqin@loongson.cn>

Remove the "edac_" prefix from driver-local definitions to keep the
edac_ namespace reserved for EDAC core functions.

Rename edac_check(), edac_probe() and edac_remove() to
loongson_check(), loongson_probe() and loongson_remove(), respectively,
and rename struct loongson_edac_pvt, loongson_edac_driver and
loongson_edac_acpi_match to loongson_pvt, loongson_driver and
loongson_acpi_match, respectively. The shorter names are unambiguous
since they are all file-local.

Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
---
 drivers/edac/loongson_edac.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index 3ed4d34a33..5dfa41e877 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -13,7 +13,7 @@
 
 #define ECC_CS_COUNT_REG	0x18
 
-struct loongson_edac_pvt {
+struct loongson_pvt {
 	void __iomem *ecc_base;
 
 	/*
@@ -27,7 +27,7 @@ struct loongson_edac_pvt {
 
 static int read_ecc(struct mem_ctl_info *mci)
 {
-	struct loongson_edac_pvt *pvt = mci->pvt_info;
+	struct loongson_pvt *pvt = mci->pvt_info;
 	u64 ecc;
 	int cs;
 
@@ -41,9 +41,9 @@ static int read_ecc(struct mem_ctl_info *mci)
 	return cs;
 }
 
-static void edac_check(struct mem_ctl_info *mci)
+static void loongson_check(struct mem_ctl_info *mci)
 {
-	struct loongson_edac_pvt *pvt = mci->pvt_info;
+	struct loongson_pvt *pvt = mci->pvt_info;
 	int new, add;
 
 	new = read_ecc(mci);
@@ -74,13 +74,13 @@ static void dimm_config_init(struct mem_ctl_info *mci)
 
 static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase)
 {
-	struct loongson_edac_pvt *pvt = mci->pvt_info;
+	struct loongson_pvt *pvt = mci->pvt_info;
 
 	pvt->ecc_base = vbase;
 	pvt->last_ce_count = read_ecc(mci);
 }
 
-static int edac_probe(struct platform_device *pdev)
+static int loongson_probe(struct platform_device *pdev)
 {
 	struct edac_mc_layer layers[2];
 	struct mem_ctl_info *mci;
@@ -98,7 +98,7 @@ static int edac_probe(struct platform_device *pdev)
 	layers[1].size = 1;
 	layers[1].is_virt_csrow = true;
 	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
-			    sizeof(struct loongson_edac_pvt));
+			    sizeof(struct loongson_pvt));
 	if (mci == NULL)
 		return -ENOMEM;
 
@@ -112,7 +112,7 @@ static int edac_probe(struct platform_device *pdev)
 	mci->ctl_page_to_phys = NULL;
 	mci->pdev = &pdev->dev;
 	mci->error_desc.grain = 8;
-	mci->edac_check = edac_check;
+	mci->edac_check = loongson_check;
 
 	pvt_init(mci, vbase);
 	dimm_config_init(mci);
@@ -128,7 +128,7 @@ static int edac_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void edac_remove(struct platform_device *pdev)
+static void loongson_remove(struct platform_device *pdev)
 {
 	struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev);
 
@@ -136,21 +136,21 @@ static void edac_remove(struct platform_device *pdev)
 		edac_mc_free(mci);
 }
 
-static const struct acpi_device_id loongson_edac_acpi_match[] = {
+static const struct acpi_device_id loongson_acpi_match[] = {
 	{ .id = "LOON0010" },
 	{ }
 };
-MODULE_DEVICE_TABLE(acpi, loongson_edac_acpi_match);
+MODULE_DEVICE_TABLE(acpi, loongson_acpi_match);
 
-static struct platform_driver loongson_edac_driver = {
-	.probe		= edac_probe,
-	.remove		= edac_remove,
+static struct platform_driver loongson_driver = {
+	.probe		= loongson_probe,
+	.remove		= loongson_remove,
 	.driver		= {
 		.name	= "loongson-mc-edac",
-		.acpi_match_table = loongson_edac_acpi_match,
+		.acpi_match_table = loongson_acpi_match,
 	},
 };
-module_platform_driver(loongson_edac_driver);
+module_platform_driver(loongson_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Zhao Qunqin <zhaoqunqin@loongson.cn>");
-- 
2.47.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx
  2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
  2026-11-18  3:03 ` [PATCH v8 1/4] EDAC/loongson: Rename driver-local symbols Qunqin Zhao
@ 2026-11-18  3:03 ` Qunqin Zhao
  2026-11-18  7:45   ` Huacai Chen
  2026-11-18  3:03 ` [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method Qunqin Zhao
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-18  3:03 UTC (permalink / raw)
  To: bp
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel,
	Wang Jinwei, Yulong Wang, Dongyan Qian, Chao Li

From: Wang Jinwei <wangjinwei@loongson.cn>

On Loongson multi-node systems, memory controllers are distributed across
multiple nodes. Encode node and MC information into mc_idx so that sysfs
entries uniquely identify each controller.

The driver gets mc-idx from ACPI _DSD property if firmware provides it.
If not, it falls back to edac_device_alloc_index() for legacy firmware
compatibility.

The number of memory controllers per node (mcs-per-node) is obtained
from firmware via ACPI _DSD property, with a default of 4 for backward
compatibility. Validate that the firmware-provided value is non-zero to
prevent division by zero. The node and MC IDs are decoded from mc_idx:
    node = mc_idx / mcs_per_node
    mc = mc_idx % mcs_per_node

Cc: Yulong Wang <wangyulong@loongson.cn>
Cc: Dongyan Qian <qiandongyan@loongson.cn>
Cc: Chao Li <lichao@loongson.cn>
Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
---
 drivers/edac/loongson_edac.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index 5dfa41e877..4ee9dcb3d5 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -9,10 +9,14 @@
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include "edac_module.h"
 
 #define ECC_CS_COUNT_REG	0x18
 
+/* Memory controller index invalid due to inability to read it from ACPI, etc */
+#define MC_IDX_INVALID		BIT(16)
+
 struct loongson_pvt {
 	void __iomem *ecc_base;
 
@@ -23,6 +27,7 @@ struct loongson_pvt {
 	 * register state.
 	 */
 	int last_ce_count;
+	u32 mcs_per_node;
 };
 
 static int read_ecc(struct mem_ctl_info *mci)
@@ -44,7 +49,8 @@ static int read_ecc(struct mem_ctl_info *mci)
 static void loongson_check(struct mem_ctl_info *mci)
 {
 	struct loongson_pvt *pvt = mci->pvt_info;
-	int new, add;
+	char other_detail[64] = {0};
+	int new, add, node, mc;
 
 	new = read_ecc(mci);
 	add = new - pvt->last_ce_count;
@@ -52,8 +58,14 @@ static void loongson_check(struct mem_ctl_info *mci)
 	if (add <= 0)
 		return;
 
+	if (mci->mc_idx < MC_IDX_INVALID) {
+		node = mci->mc_idx / pvt->mcs_per_node;
+		mc = mci->mc_idx % pvt->mcs_per_node;
+		snprintf(other_detail, sizeof(other_detail), "node:%d mc:%d", node, mc);
+	}
+
 	edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, add,
-			     0, 0, 0, 0, 0, -1, "error", "");
+			     0, 0, 0, 0, 0, -1, "error", other_detail);
 }
 
 static void dimm_config_init(struct mem_ctl_info *mci)
@@ -72,19 +84,22 @@ 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)
+static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase, u32 mcs_per_node)
 {
 	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;
 }
 
 static int loongson_probe(struct platform_device *pdev)
 {
 	struct edac_mc_layer layers[2];
 	struct mem_ctl_info *mci;
+	struct device *dev = &pdev->dev;
 	void __iomem *vbase;
+	u32 mcs_per_node;
 	int ret;
 
 	vbase = devm_platform_ioremap_resource(pdev, 0);
@@ -102,7 +117,6 @@ static int loongson_probe(struct platform_device *pdev)
 	if (mci == NULL)
 		return -ENOMEM;
 
-	mci->mc_idx = edac_device_alloc_index();
 	mci->mtype_cap = MEM_FLAG_RDDR4;
 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
 	mci->edac_cap = EDAC_FLAG_NONE;
@@ -114,7 +128,13 @@ static int loongson_probe(struct platform_device *pdev)
 	mci->error_desc.grain = 8;
 	mci->edac_check = loongson_check;
 
-	pvt_init(mci, vbase);
+	if (device_property_read_u32(dev, "mc-idx", &mci->mc_idx))
+		mci->mc_idx = edac_device_alloc_index() | MC_IDX_INVALID;
+
+	if (device_property_read_u32(dev, "mcs-per-node", &mcs_per_node) || mcs_per_node == 0)
+		mcs_per_node = 4;
+
+	pvt_init(mci, vbase, mcs_per_node);
 	dimm_config_init(mci);
 
 	ret = edac_mc_add_mc(mci);
-- 
2.47.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method
  2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
  2026-11-18  3:03 ` [PATCH v8 1/4] EDAC/loongson: Rename driver-local symbols Qunqin Zhao
  2026-11-18  3:03 ` [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx Qunqin Zhao
@ 2026-11-18  3:03 ` Qunqin Zhao
  2026-11-27 23:23   ` Borislav Petkov
  2026-11-18  3:03 ` [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access Qunqin Zhao
  2026-11-27 23:40 ` [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Borislav Petkov
  4 siblings, 1 reply; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-18  3:03 UTC (permalink / raw)
  To: bp
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel,
	Wang Jinwei, Dongyan Qian, Chao Li, Huacai Chen

From: Wang Jinwei <wangjinwei@loongson.cn>

Add support to retrieve DIMM size from ACPI _DSM method instead
of using hardcoded values.

1. Add loongson_get_dimm_size_acpi() to call ACPI _DSM method
   to Get DIMM size in MB.

2. Update dimm_config_init() to use the size from ACPI, with
   fallback to default 1 MB if ACPI method fails.

3. Add ACPI UUID and DSM function definitions for EDAC.

The DIMM size is passed from UEFI through ACPI OperationRegion
and _DSM method, enabling correct display of memory size in
/sys/devices/system/edac/mc/mc*/size_mb.

Cc: Dongyan Qian <qiandongyan@loongson.cn>
Cc: Chao Li <lichao@loongson.cn>
Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
---
 drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index 4ee9dcb3d5..413ca654b4 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -13,6 +13,8 @@
 #include "edac_module.h"
 
 #define ECC_CS_COUNT_REG	0x18
+#define LOONGSON_EDAC_DSM_UUID "65d0431b-7eb8-46df-b914-b7d568553140"
+#define LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE   1
 
 /* Memory controller index invalid due to inability to read it from ACPI, etc */
 #define MC_IDX_INVALID		BIT(16)
@@ -68,13 +70,39 @@ static void loongson_check(struct mem_ctl_info *mci)
 			     0, 0, 0, 0, 0, -1, "error", other_detail);
 }
 
+static u32 loongson_get_dimm_size_acpi(struct device *dev)
+{
+	acpi_handle handle = ACPI_HANDLE(dev);
+	union acpi_object *obj;
+	u32 size_mb = 1;
+	guid_t guid;
+
+	if (!handle)
+		return size_mb;
+
+	if (guid_parse(LOONGSON_EDAC_DSM_UUID, &guid))
+		return size_mb;
+
+	obj = acpi_evaluate_dsm(handle, &guid, 0,
+				LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE, NULL);
+	if (!obj)
+		return size_mb;
+
+	if (obj->type == ACPI_TYPE_INTEGER)
+		size_mb = (u32)obj->integer.value;
+
+	ACPI_FREE(obj);
+	return size_mb;
+}
+
 static void dimm_config_init(struct mem_ctl_info *mci)
 {
 	struct dimm_info *dimm;
+	struct device *dev = mci->pdev;
 	u32 size, npages;
 
-	/* size not used */
-	size = -1;
+	size = loongson_get_dimm_size_acpi(dev);
+
 	npages = MiB_TO_PAGES(size);
 
 	dimm = edac_get_dimm(mci, 0, 0, 0);
-- 
2.47.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access
  2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
                   ` (2 preceding siblings ...)
  2026-11-18  3:03 ` [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method Qunqin Zhao
@ 2026-11-18  3:03 ` Qunqin Zhao
  2026-11-18  7:46   ` Huacai Chen
  2026-11-27 23:25   ` Borislav Petkov
  2026-11-27 23:40 ` [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Borislav Petkov
  4 siblings, 2 replies; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-18  3:03 UTC (permalink / raw)
  To: bp
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel,
	Wu sheng, Wang Jinwei

From: Qunqin Zhao <zhaoqunqin@loongson.cn>

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.

For cross-node accesses, check CS4-7 (high 32 bits) of the ECC
count register. If the valid-cs-bits firmware property is set and
the high bits are non-zero, it indicates a timeout or random value,
so skip the report and return the previous count.

To avoid undefined behavior on 8-CS systems where valid_cs_bits=64,
guard the shift with a bounds check (valid_cs_bits < 64).

Signed-off-by: Wu sheng <wusheng@loongson.cn>
Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
---
 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 413ca654b4..50959d4429 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -30,6 +30,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)
@@ -39,11 +40,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,13 +123,15 @@ 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 loongson_probe(struct platform_device *pdev)
@@ -127,7 +140,7 @@ static int loongson_probe(struct platform_device *pdev)
 	struct mem_ctl_info *mci;
 	struct device *dev = &pdev->dev;
 	void __iomem *vbase;
-	u32 mcs_per_node;
+	u32 mcs_per_node, valid_cs_bits;
 	int ret;
 
 	vbase = devm_platform_ioremap_resource(pdev, 0);
@@ -162,7 +175,10 @@ static int loongson_probe(struct platform_device *pdev)
 	if (device_property_read_u32(dev, "mcs-per-node", &mcs_per_node) || mcs_per_node == 0)
 		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);
-- 
2.47.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx
  2026-11-18  3:03 ` [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx Qunqin Zhao
@ 2026-11-18  7:45   ` Huacai Chen
  0 siblings, 0 replies; 13+ messages in thread
From: Huacai Chen @ 2026-11-18  7:45 UTC (permalink / raw)
  To: Qunqin Zhao
  Cc: bp, tony.luck, linux-edac, zhaoqunqin, linux-kernel, Wang Jinwei,
	Yulong Wang, Dongyan Qian, Chao Li

Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>

On Wed, Nov 18, 2026 at 11:04 AM Qunqin Zhao <zhaoqunqin@163.com> wrote:
>
> From: Wang Jinwei <wangjinwei@loongson.cn>
>
> On Loongson multi-node systems, memory controllers are distributed across
> multiple nodes. Encode node and MC information into mc_idx so that sysfs
> entries uniquely identify each controller.
>
> The driver gets mc-idx from ACPI _DSD property if firmware provides it.
> If not, it falls back to edac_device_alloc_index() for legacy firmware
> compatibility.
>
> The number of memory controllers per node (mcs-per-node) is obtained
> from firmware via ACPI _DSD property, with a default of 4 for backward
> compatibility. Validate that the firmware-provided value is non-zero to
> prevent division by zero. The node and MC IDs are decoded from mc_idx:
>     node = mc_idx / mcs_per_node
>     mc = mc_idx % mcs_per_node
>
> Cc: Yulong Wang <wangyulong@loongson.cn>
> Cc: Dongyan Qian <qiandongyan@loongson.cn>
> Cc: Chao Li <lichao@loongson.cn>
> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> ---
>  drivers/edac/loongson_edac.c | 30 +++++++++++++++++++++++++-----
>  1 file changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
> index 5dfa41e877..4ee9dcb3d5 100644
> --- a/drivers/edac/loongson_edac.c
> +++ b/drivers/edac/loongson_edac.c
> @@ -9,10 +9,14 @@
>  #include <linux/io-64-nonatomic-lo-hi.h>
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
> +#include <linux/property.h>
>  #include "edac_module.h"
>
>  #define ECC_CS_COUNT_REG       0x18
>
> +/* Memory controller index invalid due to inability to read it from ACPI, etc */
> +#define MC_IDX_INVALID         BIT(16)
> +
>  struct loongson_pvt {
>         void __iomem *ecc_base;
>
> @@ -23,6 +27,7 @@ struct loongson_pvt {
>          * register state.
>          */
>         int last_ce_count;
> +       u32 mcs_per_node;
>  };
>
>  static int read_ecc(struct mem_ctl_info *mci)
> @@ -44,7 +49,8 @@ static int read_ecc(struct mem_ctl_info *mci)
>  static void loongson_check(struct mem_ctl_info *mci)
>  {
>         struct loongson_pvt *pvt = mci->pvt_info;
> -       int new, add;
> +       char other_detail[64] = {0};
> +       int new, add, node, mc;
>
>         new = read_ecc(mci);
>         add = new - pvt->last_ce_count;
> @@ -52,8 +58,14 @@ static void loongson_check(struct mem_ctl_info *mci)
>         if (add <= 0)
>                 return;
>
> +       if (mci->mc_idx < MC_IDX_INVALID) {
> +               node = mci->mc_idx / pvt->mcs_per_node;
> +               mc = mci->mc_idx % pvt->mcs_per_node;
> +               snprintf(other_detail, sizeof(other_detail), "node:%d mc:%d", node, mc);
> +       }
> +
>         edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, add,
> -                            0, 0, 0, 0, 0, -1, "error", "");
> +                            0, 0, 0, 0, 0, -1, "error", other_detail);
>  }
>
>  static void dimm_config_init(struct mem_ctl_info *mci)
> @@ -72,19 +84,22 @@ 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)
> +static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase, u32 mcs_per_node)
>  {
>         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;
>  }
>
>  static int loongson_probe(struct platform_device *pdev)
>  {
>         struct edac_mc_layer layers[2];
>         struct mem_ctl_info *mci;
> +       struct device *dev = &pdev->dev;
>         void __iomem *vbase;
> +       u32 mcs_per_node;
>         int ret;
>
>         vbase = devm_platform_ioremap_resource(pdev, 0);
> @@ -102,7 +117,6 @@ static int loongson_probe(struct platform_device *pdev)
>         if (mci == NULL)
>                 return -ENOMEM;
>
> -       mci->mc_idx = edac_device_alloc_index();
>         mci->mtype_cap = MEM_FLAG_RDDR4;
>         mci->edac_ctl_cap = EDAC_FLAG_NONE;
>         mci->edac_cap = EDAC_FLAG_NONE;
> @@ -114,7 +128,13 @@ static int loongson_probe(struct platform_device *pdev)
>         mci->error_desc.grain = 8;
>         mci->edac_check = loongson_check;
>
> -       pvt_init(mci, vbase);
> +       if (device_property_read_u32(dev, "mc-idx", &mci->mc_idx))
> +               mci->mc_idx = edac_device_alloc_index() | MC_IDX_INVALID;
> +
> +       if (device_property_read_u32(dev, "mcs-per-node", &mcs_per_node) || mcs_per_node == 0)
> +               mcs_per_node = 4;
> +
> +       pvt_init(mci, vbase, mcs_per_node);
>         dimm_config_init(mci);
>
>         ret = edac_mc_add_mc(mci);
> --
> 2.47.2
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access
  2026-11-18  3:03 ` [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access Qunqin Zhao
@ 2026-11-18  7:46   ` Huacai Chen
  2026-11-27 23:25   ` Borislav Petkov
  1 sibling, 0 replies; 13+ messages in thread
From: Huacai Chen @ 2026-11-18  7:46 UTC (permalink / raw)
  To: Qunqin Zhao
  Cc: bp, tony.luck, linux-edac, zhaoqunqin, linux-kernel, Wu sheng,
	Wang Jinwei

Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>

On Wed, Nov 18, 2026 at 11:04 AM Qunqin Zhao <zhaoqunqin@163.com> wrote:
>
> From: Qunqin Zhao <zhaoqunqin@loongson.cn>
>
> 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.
>
> For cross-node accesses, check CS4-7 (high 32 bits) of the ECC
> count register. If the valid-cs-bits firmware property is set and
> the high bits are non-zero, it indicates a timeout or random value,
> so skip the report and return the previous count.
>
> To avoid undefined behavior on 8-CS systems where valid_cs_bits=64,
> guard the shift with a bounds check (valid_cs_bits < 64).
>
> Signed-off-by: Wu sheng <wusheng@loongson.cn>
> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> ---
>  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 413ca654b4..50959d4429 100644
> --- a/drivers/edac/loongson_edac.c
> +++ b/drivers/edac/loongson_edac.c
> @@ -30,6 +30,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)
> @@ -39,11 +40,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,13 +123,15 @@ 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 loongson_probe(struct platform_device *pdev)
> @@ -127,7 +140,7 @@ static int loongson_probe(struct platform_device *pdev)
>         struct mem_ctl_info *mci;
>         struct device *dev = &pdev->dev;
>         void __iomem *vbase;
> -       u32 mcs_per_node;
> +       u32 mcs_per_node, valid_cs_bits;
>         int ret;
>
>         vbase = devm_platform_ioremap_resource(pdev, 0);
> @@ -162,7 +175,10 @@ static int loongson_probe(struct platform_device *pdev)
>         if (device_property_read_u32(dev, "mcs-per-node", &mcs_per_node) || mcs_per_node == 0)
>                 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);
> --
> 2.47.2
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method
  2026-11-18  3:03 ` [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method Qunqin Zhao
@ 2026-11-27 23:23   ` Borislav Petkov
  2026-11-30  2:47     ` Qunqin Zhao
  0 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2026-11-27 23:23 UTC (permalink / raw)
  To: Qunqin Zhao
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel,
	Wang Jinwei, Dongyan Qian, Chao Li, Huacai Chen

On Wed, Nov 18, 2026 at 11:03:29AM +0800, Qunqin Zhao wrote:
> From: Wang Jinwei <wangjinwei@loongson.cn>
> 
> Add support to retrieve DIMM size from ACPI _DSM method instead
> of using hardcoded values.
> 
> 1. Add loongson_get_dimm_size_acpi() to call ACPI _DSM method
>    to Get DIMM size in MB.
> 
> 2. Update dimm_config_init() to use the size from ACPI, with
>    fallback to default 1 MB if ACPI method fails.
> 
> 3. Add ACPI UUID and DSM function definitions for EDAC.
> 
> The DIMM size is passed from UEFI through ACPI OperationRegion
> and _DSM method, enabling correct display of memory size in
> /sys/devices/system/edac/mc/mc*/size_mb.

Please, do not talk about *what* the patch is doing in the commit message
- that should be obvious from the diff itself. Rather, concentrate on the
*why* it needs to be done and why your patch exists.

It is perfectly fine to explain non-trivial aspects of the code the patch is
touching but do not regurgitate what it does.

See also https://docs.kernel.org/process/submitting-patches.html for
additional inspiration.
 
> Cc: Dongyan Qian <qiandongyan@loongson.cn>
> Cc: Chao Li <lichao@loongson.cn>
> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
> index 4ee9dcb3d5..413ca654b4 100644
> --- a/drivers/edac/loongson_edac.c
> +++ b/drivers/edac/loongson_edac.c
> @@ -13,6 +13,8 @@
>  #include "edac_module.h"
>  
>  #define ECC_CS_COUNT_REG	0x18
> +#define LOONGSON_EDAC_DSM_UUID "65d0431b-7eb8-46df-b914-b7d568553140"
> +#define LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE   1

Are you serious? Can you make that define longer?!?

Didn't I already told you to zap all those "loongson" prefixes from static
objects?

>  
>  /* Memory controller index invalid due to inability to read it from ACPI, etc */
>  #define MC_IDX_INVALID		BIT(16)
> @@ -68,13 +70,39 @@ static void loongson_check(struct mem_ctl_info *mci)
>  			     0, 0, 0, 0, 0, -1, "error", other_detail);
>  }

>  static void dimm_config_init(struct mem_ctl_info *mci)
>  {
>  	struct dimm_info *dimm;
> +	struct device *dev = mci->pdev;
>  	u32 size, npages;

This tree's preferred ordering of variable declarations at the beginning of
a function is reverse fir tree order::

	struct long_struct_name *descriptive_name;
	unsigned long foo, bar;
	unsigned int tmp;
	int ret;

The above is faster to parse than the reverse ordering::

	int ret;
	unsigned int tmp;
	unsigned long foo, bar;
	struct long_struct_name *descriptive_name;

And even more so than random ordering::

	unsigned long foo, bar;
	int ret;
	struct long_struct_name *descriptive_name;
	unsigned int tmp;

I went and did it for you ontop again.

Please make sure you go over the changes I did and keep them in mind next time
you send patches.

---
From: Wang Jinwei <wangjinwei@loongson.cn>
Date: Wed, 18 Nov 2026 11:03:29 +0800
Subject: [PATCH] EDAC/loongson: Get DIMM size from ACPI _DSM method

Retrieve DIMM size from the ACPI _DSM method instead of using hardcoded
values.

The DIMM size is passed from UEFI through ACPI OperationRegion and _DSM
method, enabling correct display of memory size in:

  /sys/devices/system/edac/mc/mc*/size_mb

  [ bp:
   - Massage commit message, drop text explaining what the patch does
   - Zap insanely long define
   - Zap loongson prefix from more static objects
   ]

Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://patch.msgid.link/20261118030330.25779-4-zhaoqunqin@163.com
---
 drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index d9c86d7e721b..250eba136655 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -13,6 +13,7 @@
 #include "edac_module.h"
 
 #define ECC_CS_COUNT_REG	0x18
+#define DSM_UUID		"65d0431b-7eb8-46df-b914-b7d568553140"
 
 /* Memory controller index invalid due to inability to read it from ACPI, etc */
 #define MC_IDX_INVALID		BIT(16)
@@ -68,13 +69,40 @@ static void loongson_check(struct mem_ctl_info *mci)
 			     0, 0, 0, 0, 0, -1, "error", other_detail);
 }
 
+static u32 get_dimm_size_acpi(struct device *dev)
+{
+	acpi_handle handle = ACPI_HANDLE(dev);
+	union acpi_object *obj;
+	u32 size_mb = 1;
+	guid_t guid;
+
+	if (!handle)
+		return size_mb;
+
+	if (guid_parse(DSM_UUID, &guid))
+		return size_mb;
+
+	/* 1 = DSM get DIMM size */
+	obj = acpi_evaluate_dsm(handle, &guid, 0, 1, NULL);
+	if (!obj)
+		return size_mb;
+
+	if (obj->type == ACPI_TYPE_INTEGER)
+		size_mb = (u32)obj->integer.value;
+
+	ACPI_FREE(obj);
+
+	return size_mb;
+}
+
 static void dimm_config_init(struct mem_ctl_info *mci)
 {
+	struct device *dev = mci->pdev;
 	struct dimm_info *dimm;
 	u32 size, npages;
 
-	/* size not used */
-	size = -1;
+	size = get_dimm_size_acpi(dev);
+
 	npages = MiB_TO_PAGES(size);
 
 	dimm = edac_get_dimm(mci, 0, 0, 0);
-- 
2.53.0


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access
  2026-11-18  3:03 ` [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access Qunqin Zhao
  2026-11-18  7:46   ` Huacai Chen
@ 2026-11-27 23:25   ` Borislav Petkov
  2026-11-30  3:25     ` Qunqin Zhao
  1 sibling, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2026-11-27 23:25 UTC (permalink / raw)
  To: Qunqin Zhao
  Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel,
	Wu sheng, Wang Jinwei

On Wed, Nov 18, 2026 at 11:03:30AM +0800, Qunqin Zhao wrote:
> From: Qunqin Zhao <zhaoqunqin@loongson.cn>
> 
> 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.
> 
> For cross-node accesses, check CS4-7 (high 32 bits) of the ECC
> count register. If the valid-cs-bits firmware property is set and
> the high bits are non-zero, it indicates a timeout or random value,
> so skip the report and return the previous count.
> 
> To avoid undefined behavior on 8-CS systems where valid_cs_bits=64,
> guard the shift with a bounds check (valid_cs_bits < 64).

Do NOT explain the diff in the commit message!

> 
> Signed-off-by: Wu sheng <wusheng@loongson.cn>
> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>

Do you know how SOB chains work?

Please refresh on the documentation:

https://docs.kernel.org/process/development-process.html
https://www.kernel.org/doc/html/latest/process/submitting-patches.html

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver
  2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
                   ` (3 preceding siblings ...)
  2026-11-18  3:03 ` [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access Qunqin Zhao
@ 2026-11-27 23:40 ` Borislav Petkov
  4 siblings, 0 replies; 13+ messages in thread
From: Borislav Petkov @ 2026-11-27 23:40 UTC (permalink / raw)
  To: Qunqin Zhao; +Cc: tony.luck, linux-edac, chenhuacai, zhaoqunqin, linux-kernel

On Wed, Nov 18, 2026 at 11:03:26AM +0800, Qunqin Zhao wrote:
> From: Qunqin Zhao <zhaoqunqin@loongson.cn>
> 
> This series contains four patches for the Loongson EDAC driver.

Also below.

I've pushed what I have to:

https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/log/?h=edac-drivers-loongson

You can base your patch 4 ontop.

Thx.

From: "Borislav Petkov (AMD)" <bp@alien8.de>
Date: Fri, 27 Nov 2026 15:29:30 -0800
Subject: [PATCH] EDAC/loongson: Do some more cleanups

- Zap more unnecessary prefixing
- Fixup module name string
- Other smaller cleanups

No functional changes.

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
 drivers/edac/loongson_edac.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index 250eba136655..05b95b71233e 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -47,7 +47,7 @@ static int read_ecc(struct mem_ctl_info *mci)
 	return cs;
 }
 
-static void loongson_check(struct mem_ctl_info *mci)
+static void check_for_errors(struct mem_ctl_info *mci)
 {
 	struct loongson_pvt *pvt = mci->pvt_info;
 	char other_detail[64] = {0};
@@ -121,7 +121,7 @@ static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase, u32 mcs_per_
 	pvt->mcs_per_node = mcs_per_node;
 }
 
-static int loongson_probe(struct platform_device *pdev)
+static int driver_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct edac_mc_layer layers[2];
@@ -140,21 +140,20 @@ static int loongson_probe(struct platform_device *pdev)
 	layers[1].type = EDAC_MC_LAYER_SLOT;
 	layers[1].size = 1;
 	layers[1].is_virt_csrow = true;
-	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers,
-			    sizeof(struct loongson_pvt));
-	if (mci == NULL)
+	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct loongson_pvt));
+	if (!mci)
 		return -ENOMEM;
 
 	mci->mtype_cap = MEM_FLAG_RDDR4;
 	mci->edac_ctl_cap = EDAC_FLAG_NONE;
 	mci->edac_cap = EDAC_FLAG_NONE;
-	mci->mod_name = "loongson_edac.c";
+	mci->mod_name = "loongson_edac";
 	mci->ctl_name = "loongson_edac_ctl";
 	mci->dev_name = "loongson_edac_dev";
 	mci->ctl_page_to_phys = NULL;
 	mci->pdev = &pdev->dev;
 	mci->error_desc.grain = 8;
-	mci->edac_check = loongson_check;
+	mci->edac_check = check_for_errors;
 
 	if (device_property_read_u32(dev, "mc-idx", &mci->mc_idx))
 		mci->mc_idx = edac_device_alloc_index() | MC_IDX_INVALID;
@@ -176,7 +175,7 @@ static int loongson_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void loongson_remove(struct platform_device *pdev)
+static void driver_remove(struct platform_device *pdev)
 {
 	struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev);
 
@@ -184,18 +183,18 @@ static void loongson_remove(struct platform_device *pdev)
 		edac_mc_free(mci);
 }
 
-static const struct acpi_device_id loongson_acpi_match[] = {
+static const struct acpi_device_id acpi_match_table[] = {
 	{ .id = "LOON0010" },
 	{ }
 };
-MODULE_DEVICE_TABLE(acpi, loongson_acpi_match);
+MODULE_DEVICE_TABLE(acpi, acpi_match_table);
 
 static struct platform_driver loongson_driver = {
-	.probe		= loongson_probe,
-	.remove		= loongson_remove,
+	.probe		= driver_probe,
+	.remove		= driver_remove,
 	.driver		= {
 		.name	= "loongson-mc-edac",
-		.acpi_match_table = loongson_acpi_match,
+		.acpi_match_table = acpi_match_table,
 	},
 };
 module_platform_driver(loongson_driver);
-- 
2.53.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method
  2026-11-27 23:23   ` Borislav Petkov
@ 2026-11-30  2:47     ` Qunqin Zhao
  0 siblings, 0 replies; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-30  2:47 UTC (permalink / raw)
  To: Borislav Petkov, Qunqin Zhao
  Cc: tony.luck, linux-edac, chenhuacai, linux-kernel, Wang Jinwei,
	Dongyan Qian, Chao Li, Huacai Chen


在 2026/11/28 07:23, Borislav Petkov 写道:
> On Wed, Nov 18, 2026 at 11:03:29AM +0800, Qunqin Zhao wrote:
>> From: Wang Jinwei <wangjinwei@loongson.cn>
>>
>> Add support to retrieve DIMM size from ACPI _DSM method instead
>> of using hardcoded values.
>>
>> 1. Add loongson_get_dimm_size_acpi() to call ACPI _DSM method
>>    to Get DIMM size in MB.
>>
>> 2. Update dimm_config_init() to use the size from ACPI, with
>>    fallback to default 1 MB if ACPI method fails.
>>
>> 3. Add ACPI UUID and DSM function definitions for EDAC.
>>
>> The DIMM size is passed from UEFI through ACPI OperationRegion
>> and _DSM method, enabling correct display of memory size in
>> /sys/devices/system/edac/mc/mc*/size_mb.
> Please, do not talk about *what* the patch is doing in the commit message
> - that should be obvious from the diff itself. Rather, concentrate on the
> *why* it needs to be done and why your patch exists.
>
> It is perfectly fine to explain non-trivial aspects of the code the patch is
> touching but do not regurgitate what it does.
>
> See also https://docs.kernel.org/process/submitting-patches.html for
> additional inspiration.
Understood, thanks.
>  
>> Cc: Dongyan Qian <qiandongyan@loongson.cn>
>> Cc: Chao Li <lichao@loongson.cn>
>> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
>> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
>> Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
>> ---
>>  drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
>>  1 file changed, 30 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
>> index 4ee9dcb3d5..413ca654b4 100644
>> --- a/drivers/edac/loongson_edac.c
>> +++ b/drivers/edac/loongson_edac.c
>> @@ -13,6 +13,8 @@
>>  #include "edac_module.h"
>>  
>>  #define ECC_CS_COUNT_REG	0x18
>> +#define LOONGSON_EDAC_DSM_UUID "65d0431b-7eb8-46df-b914-b7d568553140"
>> +#define LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE   1
> Are you serious? Can you make that define longer?!?
DSM_UUID looks better. That's a nice cleanup.
> Didn't I already told you to zap all those "loongson" prefixes from static
> objects?
Sorry. Will keep that in mind.
>>  
>>  /* Memory controller index invalid due to inability to read it from ACPI, etc */
>>  #define MC_IDX_INVALID		BIT(16)
>> @@ -68,13 +70,39 @@ static void loongson_check(struct mem_ctl_info *mci)
>>  			     0, 0, 0, 0, 0, -1, "error", other_detail);
>>  }
>>  static void dimm_config_init(struct mem_ctl_info *mci)
>>  {
>>  	struct dimm_info *dimm;
>> +	struct device *dev = mci->pdev;
>>  	u32 size, npages;
> This tree's preferred ordering of variable declarations at the beginning of
> a function is reverse fir tree order::
>
> 	struct long_struct_name *descriptive_name;
> 	unsigned long foo, bar;
> 	unsigned int tmp;
> 	int ret;
>
> The above is faster to parse than the reverse ordering::
>
> 	int ret;
> 	unsigned int tmp;
> 	unsigned long foo, bar;
> 	struct long_struct_name *descriptive_name;
>
> And even more so than random ordering::
>
> 	unsigned long foo, bar;
> 	int ret;
> 	struct long_struct_name *descriptive_name;
> 	unsigned int tmp;
>
> I went and did it for you ontop again.
>
> Please make sure you go over the changes I did and keep them in mind next time
> you send patches.

Thanks. I've gone through your changes already and will keep them in mind for future patches.

[PATCH 1/4]:

1.  Drop text explaining what the patch does in the commit message

[PATCH 2/4]:

1.  Drop text explaining what the patch does in the commit message

2. Reorder the variable declarations

+ struct device *dev = &pdev->dev; struct edac_mc_layer layers[2];

[PATCH 3/4]: 

1.  Drop text explaining what the patch does in the commit message

2. Drop LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE macro

3. LOONGSON_EDAC_DSM_UUID -> DSM_UUID

4. loongson_get_dimm_size_acpi -> get_dimm_size_acpi

5. Reorder the variable declarations

+	struct device *dev = mci->pdev;
 	struct dimm_info *dimm;

Qunqin,
Thanks.

>
> ---
> From: Wang Jinwei <wangjinwei@loongson.cn>
> Date: Wed, 18 Nov 2026 11:03:29 +0800
> Subject: [PATCH] EDAC/loongson: Get DIMM size from ACPI _DSM method
>
> Retrieve DIMM size from the ACPI _DSM method instead of using hardcoded
> values.
>
> The DIMM size is passed from UEFI through ACPI OperationRegion and _DSM
> method, enabling correct display of memory size in:
>
>   /sys/devices/system/edac/mc/mc*/size_mb
>
>   [ bp:
>    - Massage commit message, drop text explaining what the patch does
>    - Zap insanely long define
>    - Zap loongson prefix from more static objects
>    ]
>
> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> Link: https://patch.msgid.link/20261118030330.25779-4-zhaoqunqin@163.com
> ---
>  drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
> index d9c86d7e721b..250eba136655 100644
> --- a/drivers/edac/loongson_edac.c
> +++ b/drivers/edac/loongson_edac.c
> @@ -13,6 +13,7 @@
>  #include "edac_module.h"
>  
>  #define ECC_CS_COUNT_REG	0x18
> +#define DSM_UUID		"65d0431b-7eb8-46df-b914-b7d568553140"
>  
>  /* Memory controller index invalid due to inability to read it from ACPI, etc */
>  #define MC_IDX_INVALID		BIT(16)
> @@ -68,13 +69,40 @@ static void loongson_check(struct mem_ctl_info *mci)
>  			     0, 0, 0, 0, 0, -1, "error", other_detail);
>  }
>  
> +static u32 get_dimm_size_acpi(struct device *dev)
> +{
> +	acpi_handle handle = ACPI_HANDLE(dev);
> +	union acpi_object *obj;
> +	u32 size_mb = 1;
> +	guid_t guid;
> +
> +	if (!handle)
> +		return size_mb;
> +
> +	if (guid_parse(DSM_UUID, &guid))
> +		return size_mb;
> +
> +	/* 1 = DSM get DIMM size */
> +	obj = acpi_evaluate_dsm(handle, &guid, 0, 1, NULL);
> +	if (!obj)
> +		return size_mb;
> +
> +	if (obj->type == ACPI_TYPE_INTEGER)
> +		size_mb = (u32)obj->integer.value;
> +
> +	ACPI_FREE(obj);
> +
> +	return size_mb;
> +}
> +
>  static void dimm_config_init(struct mem_ctl_info *mci)
>  {
> +	struct device *dev = mci->pdev;
>  	struct dimm_info *dimm;
>  	u32 size, npages;
>  
> -	/* size not used */
> -	size = -1;
> +	size = get_dimm_size_acpi(dev);
> +
>  	npages = MiB_TO_PAGES(size);
>  
>  	dimm = edac_get_dimm(mci, 0, 0, 0);


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access
  2026-11-27 23:25   ` Borislav Petkov
@ 2026-11-30  3:25     ` Qunqin Zhao
  2026-11-30 18:42       ` Borislav Petkov
  0 siblings, 1 reply; 13+ messages in thread
From: Qunqin Zhao @ 2026-11-30  3:25 UTC (permalink / raw)
  To: Borislav Petkov, Qunqin Zhao
  Cc: tony.luck, linux-edac, chenhuacai, linux-kernel, Wu sheng, Wang Jinwei


在 2026/11/28 07:25, Borislav Petkov 写道:
> On Wed, Nov 18, 2026 at 11:03:30AM +0800, Qunqin Zhao wrote:
>> From: Qunqin Zhao <zhaoqunqin@loongson.cn>
>>
>> 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.
>>
>> For cross-node accesses, check CS4-7 (high 32 bits) of the ECC
>> count register. If the valid-cs-bits firmware property is set and
>> the high bits are non-zero, it indicates a timeout or random value,
>> so skip the report and return the previous count.
>>
>> To avoid undefined behavior on 8-CS systems where valid_cs_bits=64,
>> guard the shift with a bounds check (valid_cs_bits < 64).
> Do NOT explain the diff in the commit message!
Will fix.
>
>> Signed-off-by: Wu sheng <wusheng@loongson.cn>
>> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
>> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> Do you know how SOB chains work?
>
> Please refresh on the documentation:
>
> https://docs.kernel.org/process/development-process.html
> https://www.kernel.org/doc/html/latest/process/submitting-patches.html

As documented in  https://www.kernel.org/doc/html/latest/process/submitting-patches.html

"Any further SoBs (Signed-off-by:’s) following the author’s SoB are from people 

handling and transporting the patch, but were not involved in its development. SoB 

chains should reflect the real route a patch took as it was propagated to the maintainers 

and ultimately to Linus, with the first SoB entry signalling primary authorship of a 

single author."

Perhaps I should do it this way:

Co-developed-by: Wu sheng <wusheng@loongson.cn> Signed-off-by: Wu sheng <wusheng@loongson.cn>
Co-developed-by: Wang Jinwei <wangjinwei@loongson.cn> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>

Qunqin,

Thanks.

>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access
  2026-11-30  3:25     ` Qunqin Zhao
@ 2026-11-30 18:42       ` Borislav Petkov
  0 siblings, 0 replies; 13+ messages in thread
From: Borislav Petkov @ 2026-11-30 18:42 UTC (permalink / raw)
  To: Qunqin Zhao
  Cc: Qunqin Zhao, tony.luck, linux-edac, chenhuacai, linux-kernel,
	Wu sheng, Wang Jinwei

On Mon, Nov 30, 2026 at 11:25:50AM +0800, Qunqin Zhao wrote:
> "Any further SoBs (Signed-off-by:’s) following the author’s SoB are from people 
> 
> handling and transporting the patch, but were not involved in its development. SoB 

This says "NOT involved in its development" - "not" capitalized by me.

> chains should reflect the real route a patch took as it was propagated to the maintainers 
> 
> and ultimately to Linus, with the first SoB entry signalling primary authorship of a 
> 
> single author."
> 
> Perhaps I should do it this way:
> 
> Co-developed-by: Wu sheng <wusheng@loongson.cn> Signed-off-by: Wu sheng <wusheng@loongson.cn>
> Co-developed-by: Wang Jinwei <wangjinwei@loongson.cn> Signed-off-by: Wang Jinwei <wangjinwei@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>

However, you're marking Sheng and Jinwei as co-authors and you're the main
author.

Does that accurately represent how this patch came to be?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-11-30 18:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  3:03 [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Qunqin Zhao
2026-11-18  3:03 ` [PATCH v8 1/4] EDAC/loongson: Rename driver-local symbols Qunqin Zhao
2026-11-18  3:03 ` [PATCH v8 2/4] EDAC/loongson: Encode node and MC info into mc_idx Qunqin Zhao
2026-11-18  7:45   ` Huacai Chen
2026-11-18  3:03 ` [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method Qunqin Zhao
2026-11-27 23:23   ` Borislav Petkov
2026-11-30  2:47     ` Qunqin Zhao
2026-11-18  3:03 ` [PATCH v8 4/4] EDAC/loongson: Add CS4-7 timeout filter for cross-node access Qunqin Zhao
2026-11-18  7:46   ` Huacai Chen
2026-11-27 23:25   ` Borislav Petkov
2026-11-30  3:25     ` Qunqin Zhao
2026-11-30 18:42       ` Borislav Petkov
2026-11-27 23:40 ` [PATCH v8 0/4] EDAC/loongson: Improvements for Loongson EDAC driver Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®