Skip to contentSkip to conversation

cxl/edac: Fix the min_scrub_cycle of a region miscalculation

RFC PATCH In review Li Ming 3 participants 9 messages May 30, 2025 – Jun 3, 2025 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

RFC PATCH 1/1 cxl/edac: Fix the min_scrub_cycle of a region miscalculation

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section 8.2.10.9.11.1).

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new scrub_cycle.

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the region.

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the change.

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this way.

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +6 -2
index 2cbc664e5d62..ad243cfe00e7 100644
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)
 {
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value among
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 28 lines · Li Ming

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section 8.2.10.9.11.1).

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new scrub_cycle.

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the region.

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the change.

Quoted 4 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this way.

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-scrub)
"Supported minimum scrub cycle duration in seconds by the memory scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do this:

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

Quoted 39 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +6 -2
index 2cbc664e5d62..ad243cfe00e7 100644
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)
 {
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value among
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
Signature · 1 line
2.34.1
author reviewer
#2 lore raw
Quoted 38 lines · Alison Schofield
Quoted 28 lines · Li Ming

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section 8.2.10.9.11.1).

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new scrub_cycle.

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the region.

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the change.

Quoted 4 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this way.

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-scrub)
"Supported minimum scrub cycle duration in seconds by the memory scrubber."

Your fix, making the min the max of the mins, looks needed.

Quoted 8 lines

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do this:

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec implies the max value is FFh. You can take a look at the Table 8-222 and Table 8-223 in CXL r3.2 section 8.2.10.9.11.1.

Ming

Quoted 38 lines
Quoted 38 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +6 -2
index 2cbc664e5d62..ad243cfe00e7 100644
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)
 {
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value among
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
Signature · 1 line
2.34.1
#3 lore raw
In reply to Alison Schofield
Quoted 52 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 28 lines · Li Ming

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section 8.2.10.9.11.1).

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new scrub_cycle.

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the region.

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the change.

Quoted 4 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this way.

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac- scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

Quoted 7 lines

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do this:

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of patrol scrub cycle field.

Thanks,
Shiju

Quoted 44 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 13 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c index renamed from drivers/cxl/core/edac.c +0 -0

2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx, · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 10 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value

among

Quoted 11 lines
drivers/cxl/core/edac.c +3 -2
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
--

2.34.1

maintainer
#4 lore raw
Quoted 55 lines · Shiju Jose
Quoted 55 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 28 lines · Li Ming

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section 8.2.10.9.11.1).

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new scrub_cycle.

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the region.

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the change.

Quoted 4 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this way.

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac- scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do this:

Quoted 7 lines
Quoted 4 lines

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of patrol scrub cycle field.

Understand that now, thanks. I'm still wondering if both these deserve more explanation in Documentation/ABI/testing/sysfs-edac-scrub explaining the calculations. Like if the device represents an aggregate of devices, like a region, the min scrub cycle is the max of the mins, whereas if the device is a single, it's exactly what the device returned. And for max, explaining what you replied above.

Regardless of this noise I'm making about the Docs.. I think Ming should go ahead and v1 the fix for the min calc.

--Alison

Quoted 48 lines

Thanks,
Shiju

Quoted 44 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 13 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c index renamed from drivers/cxl/core/edac.c +0 -0

2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx, · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 10 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value

among

Quoted 11 lines
drivers/cxl/core/edac.c +3 -2
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
--

2.34.1

#5 lore raw
Quoted 82 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 02 June 2025 17:48
To: Shiju Jose <[email protected]>
Cc: Li Ming <[email protected]>; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 12 lines · Shiju Jose
Quoted 12 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 6 lines
Quoted 6 lines · Li Ming
Quoted 5 lines

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section

8.2.10.9.11.1).

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new

scrub_cycle.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the

region.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the

change.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this

way.

Quoted 11 lines
Quoted 11 lines

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-
scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do

this:

Quoted 8 lines
Quoted 5 lines

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of

Quoted 8 lines

patrol scrub cycle field.

Understand that now, thanks. I'm still wondering if both these deserve more explanation in Documentation/ABI/testing/sysfs-edac-scrub
explaining the calculations. Like if the device represents an aggregate of devices, like a region, the min scrub cycle is the max of the mins, whereas if the device is a single, it's exactly what the device returned. And for max, explaining what you replied above.

Not sure is it appropriate to add these CXL scrub specific details to the generic file Documentation/ABI/testing/sysfs-edac-scrub?

CXL region specific details were added under section 1.2. Region based scrubbing of Documentation/edac/scrub.rst. May be better add these details for CXL specific min and max scrub cycle calculation to the Documentation/edac/scrub.rst?

How do you want to post these suggested doc changes, in a follow-up patch now?

Thanks,
Shiju

Quoted 55 lines

Regardless of this noise I'm making about the Docs.. I think Ming should go ahead and v1 the fix for the min calc.

--Alison

Quoted 49 lines

Thanks,
Shiju

Quoted 45 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 14 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +0 -0

index
2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx, · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 10 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value

among

Quoted 11 lines
drivers/cxl/core/edac.c +3 -2
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
--

2.34.1

author reviewer
#6 lore raw
Quoted 87 lines · Shiju Jose
Quoted 76 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 02 June 2025 17:48
To: Shiju Jose <[email protected]>
Cc: Li Ming <[email protected]>; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 12 lines · Shiju Jose
Quoted 12 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 6 lines
Quoted 6 lines · Li Ming
Quoted 5 lines

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section

8.2.10.9.11.1).

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new

scrub_cycle.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the

region.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the

change.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this

way.

Quoted 10 lines
Quoted 10 lines

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-
scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do

this:

Quoted 7 lines
Quoted 4 lines

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of

Quoted 8 lines

patrol scrub cycle field.

Understand that now, thanks. I'm still wondering if both these deserve more explanation in Documentation/ABI/testing/sysfs-edac-scrub
explaining the calculations. Like if the device represents an aggregate of devices, like a region, the min scrub cycle is the max of the mins, whereas if the device is a single, it's exactly what the device returned. And for max, explaining what you replied above.

Not sure is it appropriate to add these CXL scrub specific details to the generic file Documentation/ABI/testing/sysfs-edac-scrub?

Quoted 8 lines

CXL region specific details were added under section 1.2. Region based scrubbing of Documentation/edac/scrub.rst. May be better add these details for CXL specific min and max scrub cycle calculation to the Documentation/edac/scrub.rst?

How do you want to post these suggested doc changes, in a follow-up patch now?

Thanks,
Shiju

I can include the doc changes in next version.

Thanks

Ming

Quoted 50 lines
Quoted 50 lines

Regardless of this noise I'm making about the Docs.. I think Ming should go ahead and v1 the fix for the min calc.

--Alison

Quoted 45 lines

Thanks,
Shiju

Quoted 43 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 12 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +0 -0

index
2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx, · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 10 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct cxl_patrol_scrub_context *cxl_ps_ctx,

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum value

among

Quoted 11 lines
drivers/cxl/core/edac.c +3 -2
+		 * the min_scrub_cycle of all the memdevs under the region.
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle, min_scrub_cycle);
 	}
 
 	if (min_cycle)
--

2.34.1

#7 lore raw
Quoted 113 lines

-----Original Message-----
From: Li Ming <[email protected]>
Sent: 03 June 2025 00:57
To: Shiju Jose <[email protected]>; Alison Schofield <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 84 lines · Shiju Jose
Quoted 84 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 02 June 2025 17:48
To: Shiju Jose <[email protected]>
Cc: Li Ming <[email protected]>; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 12 lines · Shiju Jose
Quoted 12 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 6 lines
Quoted 6 lines · Li Ming
Quoted 5 lines

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section

8.2.10.9.11.1).

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new

scrub_cycle.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the

region.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the

change.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this

way.

Quoted 11 lines
Quoted 11 lines

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-
scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do

this:

Quoted 8 lines
Quoted 4 lines

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of

patrol scrub cycle field.

Quoted 8 lines
Quoted 7 lines

Understand that now, thanks. I'm still wondering if both these deserve more explanation in Documentation/ABI/testing/sysfs-edac-scrub
explaining the calculations. Like if the device represents an aggregate of devices, like a region, the min scrub cycle is the max of the mins, whereas if the device is a single, it's exactly what the device returned. And for max, explaining what you replied above.

Not sure is it appropriate to add these CXL scrub specific details to the generic

file

Quoted 5 lines

Documentation/ABI/testing/sysfs-edac-scrub?

CXL region specific details were added under section 1.2. Region based scrubbing of Documentation/edac/scrub.rst. May be better add these details for CXL specific min and max scrub cycle calculation to the

Documentation/edac/scrub.rst?

Quoted 1 line
Quoted 7 lines
Quoted 1 line

How do you want to post these suggested doc changes, in a follow-up patch

now?

Quoted 3 lines

Thanks,
Shiju

I can include the doc changes in next version.

Thanks Ming.

May be like this?

Documentation/ABI/testing/sysfs-edac-scrub +16 -0
index c43be90deab4..ab6014743da5 100644
@@ -49,6 +49,12 @@ Description:
                (RO) Supported minimum scrub cycle duration in seconds
                by the memory scrubber.
 
+               Device-based scrub: returns the minimum scrub cycle
+               supported by the memory device.
+
+               Region-based scrub: returns the max of minimum scrub cycles
+               supported by individual memory devices that back the region.
+
 What:          /sys/bus/edac/devices/<dev-name>/scrubX/max_cycle_duration
 Date:          March 2025
 KernelVersion: 6.15
@@ -57,6 +63,16 @@ Description:
                (RO) Supported maximum scrub cycle duration in seconds
                by the memory scrubber.
 
+               Device-based scrub: returns the maximum scrub cycle supported
+               by the memory device.
+
+               Region-based scrub: returns the min of maximum scrub cycles
+               supported by individual memory devices that back the region.
+
+               If the memory device does not provide maximum scrub cycle
+               information, return the maximum supported value of the scrub
+               cycle field.
+
 What:          /sys/bus/edac/devices/<dev-name>/scrubX/current_cycle_duration
 Date:          March 2025
 KernelVersion: 6.15
Quoted 60 lines

Thanks

Ming

Quoted 30 lines
Quoted 30 lines

Regardless of this noise I'm making about the Docs.. I think Ming should go ahead and v1 the fix for the min calc.

--Alison

Quoted 25 lines

Thanks,
Shiju

Quoted 23 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 12 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +0 -0

index
2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

Quoted 8 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 2 lines
drivers/cxl/core/edac.c +0 -0
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 137

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum

value

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

among

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 138

Quoted 1 line
drivers/cxl/core/edac.c +1 -0
+		 * the min_scrub_cycle of all the memdevs under the

region.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 141

Quoted 4 lines
drivers/cxl/core/edac.c +2 -1
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle,

min_scrub_cycle);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/cxl/core/edac.c +0 -1
 	}
 
 	if (min_cycle)
--

2.34.1

author reviewer
#8 lore raw
Quoted 146 lines · Shiju Jose
Quoted 111 lines

-----Original Message-----
From: Li Ming <[email protected]>
Sent: 03 June 2025 00:57
To: Shiju Jose <[email protected]>; Alison Schofield <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 84 lines · Shiju Jose
Quoted 84 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 02 June 2025 17:48
To: Shiju Jose <[email protected]>
Cc: Li Ming <[email protected]>; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 12 lines · Shiju Jose
Quoted 12 lines

-----Original Message-----
From: Alison Schofield <[email protected]>
Sent: 30 May 2025 19:28
To: Li Ming <[email protected]>
Cc: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>; linux- [email protected]; [email protected]
Subject: Re: [RFC PATCH 1/1] cxl/edac: Fix the min_scrub_cycle of a region miscalculation

Quoted 6 lines
Quoted 6 lines · Li Ming
Quoted 5 lines

When trying to update the scrub_cycle value of a cxl region, which means updating the scrub_cycle value of each memdev under a cxl region. cxl driver needs to guarantee the new scrub_cycle value is greater than the min_scrub_cycle value of a memdev, otherwise the updating operation will fail(Per Table 8-223 in CXL r3.2 section

8.2.10.9.11.1).

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Current implementation logic of getting the min_scrub_cycle value of a cxl region is that getting the min_scrub_cycle value of each memdevs under the cxl region, then using the minimum min_scrub_cycle value as the region's min_scrub_cycle. Checking if

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

the new scrub_cycle value is greater than this value. If yes, updating the new scrub_cycle value to each memdevs. The issue is that the new scrub_cycle value is possibly greater than the minimum min_scrub_cycle value of all memdevs but less than the maximum min_scrub_cycle value of all memdevs if memdevs have a different min_scrub_cycle value. The updating operation will always fail on these memdevs which have a greater min_scrub_cycle than the new

scrub_cycle.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The correct implementation logic is to get the maximum value of these memdevs' min_scrub_cycle, check if the new scrub_cycle value is greater than the value. If yes, the new scrub_cycle value is fit for the

region.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The change also impacts the result of cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimum min_scrub_cycle value among all memdevs under the region before the change. The interface will return the maximum min_scrub_cycle value among all memdevs under the region with the

change.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
I made this change based on my understanding on the SPEC and current CXL EDAC code, but I am not sure if it is a bug or it is designed this

way.

Quoted 11 lines
Quoted 11 lines

The attribute is defined to show (per Documentation/ABI/testing/sysfs-edac-
scrub)
"Supported minimum scrub cycle duration in seconds by the memory
scrubber."

Your fix, making the min the max of the mins, looks needed.

I took a look at the max attribute. If the min is the max on the mins, then the max should be the max of the maxes. But, not true. We do

this:

Quoted 8 lines
Quoted 4 lines

instead: *max = U8_MAX * 3600; /* Max set by register size */

The comment isn't helping me, esp since the sysfs description doesn't explain that we are using a constant max.

CXL spec r3.2 Table 8-222. Device Patrol Scrub Control Feature Readable Attributes does not define a field for "max scrub cycle supported". Thus for max scrub cycle, returning max value of (U8_MAX) of

patrol scrub cycle field.

Quoted 8 lines
Quoted 7 lines

Understand that now, thanks. I'm still wondering if both these deserve more explanation in Documentation/ABI/testing/sysfs-edac-scrub
explaining the calculations. Like if the device represents an aggregate of devices, like a region, the min scrub cycle is the max of the mins, whereas if the device is a single, it's exactly what the device returned. And for max, explaining what you replied above.

Not sure is it appropriate to add these CXL scrub specific details to the generic

file

Quoted 5 lines

Documentation/ABI/testing/sysfs-edac-scrub?

CXL region specific details were added under section 1.2. Region based scrubbing of Documentation/edac/scrub.rst. May be better add these details for CXL specific min and max scrub cycle calculation to the

Quoted 6 lines

Documentation/edac/scrub.rst?

Quoted 1 line

How do you want to post these suggested doc changes, in a follow-up patch

now?

Quoted 2 lines

Thanks,
Shiju

I can include the doc changes in next version.

Thanks Ming.

May be like this?

Documentation/ABI/testing/sysfs-edac-scrub +9 -0
index c43be90deab4..ab6014743da5 100644
@@ -49,6 +49,12 @@ Description:
                (RO) Supported minimum scrub cycle duration in seconds
                by the memory scrubber.
 
+               Device-based scrub: returns the minimum scrub cycle
+               supported by the memory device.
+
+               Region-based scrub: returns the max of minimum scrub cycles
+               supported by individual memory devices that back the region.
+
 What:          /sys/bus/edac/devices/<dev-name>/scrubX/max_cycle_duration
 Date:          March 2025
 KernelVersion: 6.15
@@ -57,6 +63,16 @@ Description:
                (RO) Supported maximum scrub cycle duration in seconds
                by the memory scrubber.
 
+               Device-based scrub: returns the maximum scrub cycle supported
+               by the memory device.
+

Documentation/ABI/testing/sysfs-edac-scrub Description: · line 78

Quoted 10 lines
Documentation/ABI/testing/sysfs-edac-scrub +7 -0
+               Region-based scrub: returns the min of maximum scrub cycles
+               supported by individual memory devices that back the region.
+
+               If the memory device does not provide maximum scrub cycle
+               information, return the maximum supported value of the scrub
+               cycle field.
+
 What:          /sys/bus/edac/devices/<dev-name>/scrubX/current_cycle_duration
 Date:          March 2025
 KernelVersion: 6.15

Sure, will do it, thanks.

Ming

Quoted 58 lines
Quoted 58 lines

Thanks

Ming

Quoted 29 lines
Quoted 29 lines

Regardless of this noise I'm making about the Docs.. I think Ming should go ahead and v1 the fix for the min calc.

--Alison

Quoted 24 lines

Thanks,
Shiju

Quoted 22 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 11 lines

base-commit: 9f153b7fb5ae45c7d426851f896487927f40e501 cxl/next

---
 drivers/cxl/core/edac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +0 -0

index
2cbc664e5d62..ad243cfe00e7 100644

drivers/cxl/core/edac.c +0 -0
@@ -103,10 +103,10 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 103

Quoted 1 line
drivers/cxl/core/edac.c +0 -0
 				u8 *cap, u16 *cycle, u8 *flags, u8 *min_cycle)

{

Quoted 8 lines
drivers/cxl/core/edac.c +1 -1
 	struct cxl_mailbox *cxl_mbox;
-	u8 min_scrub_cycle = U8_MAX;
 	struct cxl_region_params *p;
 	struct cxl_memdev *cxlmd;
 	struct cxl_region *cxlr;
+	u8 min_scrub_cycle = 0;
 	int i, ret;
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct

Quoted 2 lines
drivers/cxl/core/edac.c +0 -0
 	if (!cxl_ps_ctx->cxlr) {
@@ -133,8 +133,12 @@ static int cxl_scrub_get_attrbs(struct

cxl_patrol_scrub_context *cxl_ps_ctx,

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 137

Quoted 5 lines
drivers/cxl/core/edac.c +2 -0
 		if (ret)
 			return ret;
 
+		/*
+		 * The min_scrub_cycle of a region is the maximum

value

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

among

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 138

Quoted 1 line
drivers/cxl/core/edac.c +1 -0
+		 * the min_scrub_cycle of all the memdevs under the

region.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/cxl/core/edac.c static int cxl_scrub_get_attrbs(struct · line 141

Quoted 4 lines
drivers/cxl/core/edac.c +2 -1
+		 */
 		if (min_cycle)
-			min_scrub_cycle = min(*min_cycle, min_scrub_cycle);
+			min_scrub_cycle = max(*min_cycle,

min_scrub_cycle);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/cxl/core/edac.c +0 -1
 	}
 
 	if (min_cycle)
--

2.34.1