cxl/edac: Fix the min_scrub_cycle of a region miscalculation
Li Ming
reviewerPATCH 1/2 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.
---
Changes from RFC:
1. Add more description about the max scrub cycle. (Alison)
2. Add more description about the min scrub cycle of a region. (Alison)
3. Drop RFC tag.
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
@@ -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 max of minimum scrub +* cycles supported by memdevs that back 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
Li Ming
reviewerPATCH 2/2 cxl/Documentation: Add more description about min/max scrub cycle
user can configurare scrub cycle for a region or a memory device via sysfs interface. Currently, these interfaces have not enough description for the return value. So adding return value description to these interfaces.
--- Documentation/ABI/testing/sysfs-edac-scrub | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/ABI/testing/sysfs-edac-scrub +16 -0
@@ -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
Signature · 1 line
2.34.1
Re: [PATCH v1 2/2] cxl/Documentation: Add more description about min/max scrub cycle
Quoted 1 line · Li Ming
user can configurare scrub cycle for a region or a memory device via
s/configurare/configure/
Quoted 7 lines
sysfs interface. Currently, these interfaces have not enough description for the return value. So adding return value description to these interfaces.
Suggested-by Alison Schofield <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Li Ming <[email protected]>
Quoted 38 lines
--- Documentation/ABI/testing/sysfs-edac-scrub | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Documentation/ABI/testing/sysfs-edac-scrub +16
-0@@ -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
Re: [PATCH v1 2/2] cxl/Documentation: Add more description about min/max scrub cycle
In reply to Li MingQuoted 8 lines · On Tue, 3 Jun 2025 18:43:14 +0800 Li Ming <[email protected]> wrote:
user can configurare scrub cycle for a region or a memory device via sysfs interface. Currently, these interfaces have not enough description for the return value. So adding return value description to these interfaces.
Suggested-by Alison Schofield <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Li Ming <[email protected]>
Re: [PATCH v1 2/2] cxl/Documentation: Add more description about min/max scrub cycle
In reply to Li MingQuoted 8 lines · Li Ming
user can configurare scrub cycle for a region or a memory device via sysfs interface. Currently, these interfaces have not enough description for the return value. So adding return value description to these interfaces.
Suggested-by Alison Schofield <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Li Ming <[email protected]>
Quoted 33 lines
-----Original Message-----
From: Li Ming <[email protected]>
Sent: 03 June 2025 11:43
To: [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; Li Ming <[email protected]>
Subject: [PATCH v1 1/2] cxl/edac: Fix themin_scrub_cycleof a region miscalculationWhen trying to update the
scrub_cyclevalue of a cxl region, which means updating thescrub_cyclevalue of each memdev under a cxl region. cxl driver needs to guarantee the newscrub_cyclevalue is greater than themin_scrub_cyclevalue 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_cyclevalue of a cxl region is that getting themin_scrub_cyclevalue of each memdevs under the cxl region, then using the minimummin_scrub_cyclevalue as the region'smin_scrub_cycle. Checking if the newscrub_cyclevalue is greater than this value. If yes, updating the newscrub_cyclevalue to each memdevs. The issue is that the newscrub_cyclevalue is possibly greater than the minimummin_scrub_cyclevalue of all memdevs but less than the maximummin_scrub_cyclevalue of all memdevs if memdevs have a differentmin_scrub_cyclevalue. The updating operation will always fail on these memdevs which have a greatermin_scrub_cyclethan the newscrub_cycle.The correct implementation logic is to get the maximum value of these memdevs'
min_scrub_cycle, check if the newscrub_cyclevalue is greater than the value. If yes, the newscrub_cyclevalue is fit for the region.
Quoted 6 lines
The change also impacts the result of
cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimummin_scrub_cyclevalue among all memdevs under the region before the change. The interface will return the maximummin_scrub_cyclevalue among all memdevs under the region with the change.
Quoted 46 lines
Signed-off-by Li Ming <[email protected]>---
Changes from RFC:
1. Add more description about the max scrub cycle. (Alison) 2. Add more description about the min scrub cycle of a region. (Alison) 3. Drop RFC tag.base-commit:
9f153b7fb5ae45c7d426851f896487927f40e501cxl/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..0ef245d0bd9f100644drivers/cxl/core/edac.c +1
-1@@ -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) {drivers/cxl/core/edac.c +2
-0@@ -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 max of minimum scrub
drivers/cxl/core/edac.c +2
-0+* cycles supported by memdevs that back the region. +*/ if (
min_cycle)drivers/cxl/core/edac.c +1
-1- min_scrub_cycle =min (*min_cycle, min_scrub_cycle); + min_scrub_cycle =max (*min_cycle, min_scrub_cycle);} if (min_cycle)--
2.34.1
Quoted 22 lines · Li Ming
When trying to update the
scrub_cyclevalue of a cxl region, which means updating thescrub_cyclevalue of each memdev under a cxl region. cxl driver needs to guarantee the newscrub_cyclevalue is greater than themin_scrub_cyclevalue 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_cyclevalue of a cxl region is that getting themin_scrub_cyclevalue of each memdevs under the cxl region, then using the minimummin_scrub_cyclevalue as the region'smin_scrub_cycle. Checking if the newscrub_cyclevalue is greater than this value. If yes, updating the newscrub_cyclevalue to each memdevs. The issue is that the newscrub_cyclevalue is possibly greater than the minimummin_scrub_cyclevalue of all memdevs but less than the maximummin_scrub_cyclevalue of all memdevs if memdevs have a differentmin_scrub_cyclevalue. The updating operation will always fail on these memdevs which have a greatermin_scrub_cyclethan the newscrub_cycle.The correct implementation logic is to get the maximum value of these memdevs'
min_scrub_cycle, check if the newscrub_cyclevalue is greater than the value. If yes, the newscrub_cyclevalue is fit for the region.
Quoted 7 lines
The change also impacts the result of
cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimummin_scrub_cyclevalue among all memdevs under the region before the change. The interface will return the maximummin_scrub_cyclevalue among all memdevs under the region with the change.Signed-off-by Li Ming <[email protected]>
Quoted 41 lines
---
Changes from RFC:
1. Add more description about the max scrub cycle. (Alison)
2. Add more description about the min scrub cycle of a region. (Alison)
3. Drop RFC tag.base-commit:
9f153b7fb5ae45c7d426851f896487927f40e501cxl/next--- drivers/cxl/core/edac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/cxl/core/edac.c +6
-2@@ -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 max of minimum scrub +* cycles supported by memdevs that back 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)
Quoted 22 lines · On Tue, 3 Jun 2025 18:43:13 +0800 Li Ming <[email protected]> wrote:
When trying to update the
scrub_cyclevalue of a cxl region, which means updating thescrub_cyclevalue of each memdev under a cxl region. cxl driver needs to guarantee the newscrub_cyclevalue is greater than themin_scrub_cyclevalue 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_cyclevalue of a cxl region is that getting themin_scrub_cyclevalue of each memdevs under the cxl region, then using the minimummin_scrub_cyclevalue as the region'smin_scrub_cycle. Checking if the newscrub_cyclevalue is greater than this value. If yes, updating the newscrub_cyclevalue to each memdevs. The issue is that the newscrub_cyclevalue is possibly greater than the minimummin_scrub_cyclevalue of all memdevs but less than the maximummin_scrub_cyclevalue of all memdevs if memdevs have a differentmin_scrub_cyclevalue. The updating operation will always fail on these memdevs which have a greatermin_scrub_cyclethan the newscrub_cycle.The correct implementation logic is to get the maximum value of these memdevs'
min_scrub_cycle, check if the newscrub_cyclevalue is greater than the value. If yes, the newscrub_cyclevalue is fit for the region.
Quoted 7 lines
The change also impacts the result of
cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimummin_scrub_cyclevalue among all memdevs under the region before the change. The interface will return the maximummin_scrub_cyclevalue among all memdevs under the region with the change.Signed-off-by Li Ming <[email protected]>
Thanks for fixing this up.
Dave Jiang
maintainerQuoted 22 lines · Li Ming
When trying to update the
scrub_cyclevalue of a cxl region, which means updating thescrub_cyclevalue of each memdev under a cxl region. cxl driver needs to guarantee the newscrub_cyclevalue is greater than themin_scrub_cyclevalue 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_cyclevalue of a cxl region is that getting themin_scrub_cyclevalue of each memdevs under the cxl region, then using the minimummin_scrub_cyclevalue as the region'smin_scrub_cycle. Checking if the newscrub_cyclevalue is greater than this value. If yes, updating the newscrub_cyclevalue to each memdevs. The issue is that the newscrub_cyclevalue is possibly greater than the minimummin_scrub_cyclevalue of all memdevs but less than the maximummin_scrub_cyclevalue of all memdevs if memdevs have a differentmin_scrub_cyclevalue. The updating operation will always fail on these memdevs which have a greatermin_scrub_cyclethan the newscrub_cycle.The correct implementation logic is to get the maximum value of these memdevs'
min_scrub_cycle, check if the newscrub_cyclevalue is greater than the value. If yes, the newscrub_cyclevalue is fit for the region.
Quoted 7 lines
The change also impacts the result of
cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimummin_scrub_cyclevalue among all memdevs under the region before the change. The interface will return the maximummin_scrub_cyclevalue among all memdevs under the region with the change.Signed-off-by Li Ming <[email protected]>
Both patches applied to cxl/next
Quoted 41 lines
---
Changes from RFC:
1. Add more description about the max scrub cycle. (Alison)
2. Add more description about the min scrub cycle of a region. (Alison)
3. Drop RFC tag.base-commit:
9f153b7fb5ae45c7d426851f896487927f40e501cxl/next--- drivers/cxl/core/edac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/cxl/core/edac.c +6
-2@@ -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 max of minimum scrub +* cycles supported by memdevs that back 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)
Quoted 22 lines · Li Ming
When trying to update the
scrub_cyclevalue of a cxl region, which means updating thescrub_cyclevalue of each memdev under a cxl region. cxl driver needs to guarantee the newscrub_cyclevalue is greater than themin_scrub_cyclevalue 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_cyclevalue of a cxl region is that getting themin_scrub_cyclevalue of each memdevs under the cxl region, then using the minimummin_scrub_cyclevalue as the region'smin_scrub_cycle. Checking if the newscrub_cyclevalue is greater than this value. If yes, updating the newscrub_cyclevalue to each memdevs. The issue is that the newscrub_cyclevalue is possibly greater than the minimummin_scrub_cyclevalue of all memdevs but less than the maximummin_scrub_cyclevalue of all memdevs if memdevs have a differentmin_scrub_cyclevalue. The updating operation will always fail on these memdevs which have a greatermin_scrub_cyclethan the newscrub_cycle.The correct implementation logic is to get the maximum value of these memdevs'
min_scrub_cycle, check if the newscrub_cyclevalue is greater than the value. If yes, the newscrub_cyclevalue is fit for the region.
Quoted 7 lines
The change also impacts the result of
cxl_patrol_scrub_get_min_scrub_cycle(), the interface returned the minimummin_scrub_cyclevalue among all memdevs under the region before the change. The interface will return the maximummin_scrub_cyclevalue among all memdevs under the region with the change.Signed-off-by Li Ming <[email protected]>