drm/amdgpu: initialize ret before UMC error record loop
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: initialize ret before UMC error record loop
umc_v12_0_fill_error_record() returns ret after walking the pages reported by amdgpu_umc_lookup_bad_pages_in_a_row(). That helper can return zero entries, leaving the loop skipped and ret uninitialized.
Set ret to 0 immediately before the loop so the zero-page path reports a deterministic status instead of returning stack data.
---
v2:
- Set ret immediately before the loop instead of initializing it in the declaration, as suggested by Christian.
- Avoid describing the zero-entry case as an allocation-failure fix.
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +1 -0
@@ -690,6 +690,7 @@ static int umc_v12_0_fill_error_record(struct amdgpu_device *adev, count =amdgpu_umc_lookup_bad_pages_in_a_row (adev, ecc_err->pa_pfn <<AMDGPU_GPU_PAGE_SHIFT , page_pfn,ARRAY_SIZE (page_pfn)); + ret =0 ;for (i =0 ; i < count; i++) { ret = amdgpu_umc_fill_error_record(err_data,
Signature · 1 line
2.51.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] amdgpu_umc_lookup_bad_pages_in_a_row() incorrectly returns 0 and drops error pages if retire_unit exceeds the array length.
- [High] Infinite overcounting of de_count and duplicate bad pages if amdgpu_umc_fill_error_record() fails.
--
commit dbc37c594d1c3e76008f0f9e176701a44797cd01
Author: Ruoyu Wang <[email protected]>
drm/amdgpu: initialize ret before UMC error record loop
The commit initializes ret to 0 before iterating over the bad pages returned by amdgpu_umc_lookup_bad_pages_in_a_row() to prevent returning uninitialized data when no pages are found.
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c static int umc_v12_0_fill_error_record(struct amdgpu_device *adev, · line 692
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +0
-0@@ -690,6 +690,7 @@ static int umc_v12_0_fill_error_record(struct amdgpu_device *adev, count =amdgpu_umc_lookup_bad_pages_in_a_row (adev, ecc_err->pa_pfn <<AMDGPU_GPU_PAGE_SHIFT , page_pfn,ARRAY_SIZE (page_pfn));
[Severity: High]
This is a pre-existing issue, but does amdgpu_umc_lookup_bad_pages_in_a_row() incorrectly return 0 and drop error pages if the retire_unit exceeds the array length?
Looking at amdgpu_umc_lookup_bad_pages_in_a_row() in drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c, if adev->umc.retire_unit is greater than len, the loop terminates early via goto out:
for (i = 0; i < adev->umc.retire_unit; i++) {
if (i >= len)
goto out;
pfns[i] = err_data.err_addr[i].retired_page;
}
ret = i;
adev->umc.err_addr_cnt = err_data.err_addr_cnt;out:
kfree(err_data.err_addr);
return ret;Since ret is 0 from the previously successful call to amdgpu_umc_pages_in_a_row(), this bypasses the updates to ret and adev->umc.err_addr_cnt. Does this cause the function to incorrectly return 0 instead of len, dropping the successfully retrieved bad pages?
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c static int umc_v12_0_fill_error_record(struct amdgpu_device *adev, · line 696
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +1
-0+ ret =0 ;for (i =0 ; i < count; i++) { ret = amdgpu_umc_fill_error_record(err_data,
[Severity: High]
This is a pre-existing issue, but can this create an infinite loop of overcounting if amdgpu_umc_fill_error_record() fails?
If amdgpu_umc_fill_error_record() returns an error, the loop in umc_v12_0_fill_error_record() breaks, err_data->de_count is unconditionally incremented, and the error code is returned.
The caller umc_v12_0_query_ras_ecc_err_addr() detects this failure:
ret = umc_v12_0_fill_error_record(adev, entries[i], ras_error_status);
if (ret) {
dev_err(adev->dev, "Fail to fill umc error record, ret:%d\n", ret);
break;
}
radix_tree_tag_clear(ecc_tree,
entries[i]->pa_pfn, UMC_ECC_NEW_DETECTED_TAG);Because it breaks out of its iteration without clearing UMC_ECC_NEW_DETECTED_TAG, won't any subsequent query (like a periodic retirement worker) find the exact same entry, leading to the exact same failure sequence and infinitely incrementing the counters?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Ruoyu Wang
umc_v12_0_fill_error_record()returns ret after walking the pages reported byamdgpu_umc_lookup_bad_pages_in_a_row(). That helper can return zero entries, leaving the loop skipped and ret uninitialized.Set ret to 0 immediately before the loop so the zero-page path reports a deterministic status instead of returning stack data.
Suggested-by Christian König <[email protected]>Signed-off-by Ruoyu Wang <[email protected]>
Someone more familiar with ras should take a look as well, could be that returning -ENOENT is more appropriate here.
Quoted 23 lines
---
v2:
- Set ret immediately before the loop instead of initializing it in the declaration, as suggested by Christian.
- Avoid describing the zero-entry case as an allocation-failure fix.drivers/gpu/drm/amd/amdgpu/umc_v12_0.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +1
-1@@ -690,6 +690,7 @@ static int umc_v12_0_fill_error_record(struct amdgpu_device *adev, count =amdgpu_umc_lookup_bad_pages_in_a_row (adev, ecc_err->pa_pfn <<AMDGPU_GPU_PAGE_SHIFT , page_pfn,ARRAY_SIZE (page_pfn)); + ret =0 ;for (i =0 ; i < count; i++) { ret = amdgpu_umc_fill_error_record(err_data, --2.51.0
AMD General
[Tao] In order to align with the original logic, I prefer to "ret = -EINVAL"
Quoted 52 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Thursday, June 18, 2026 3:37 PM
To: Ruoyu Wang <[email protected]>; Deucher, Alexander <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; [email protected]; [email protected]; [email protected]; Zhang, Hawking <[email protected]>; Lazar, Lijo <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: initialize ret before UMC error record loopQuoted 9 lines · Ruoyu Wang
umc_v12_0_fill_error_record()returns ret after walking the pages reported byamdgpu_umc_lookup_bad_pages_in_a_row(). That helper can return zero entries, leaving the loop skipped and ret uninitialized.Set ret to 0 immediately before the loop so the zero-page path reports a deterministic status instead of returning stack data.
Suggested-by Christian König <[email protected]>Signed-off-by Ruoyu Wang <[email protected]>Acked-by Christian König <[email protected]>Someone more familiar with ras should take a look as well, could be that returning - ENOENT is more appropriate here.
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c static int umc_v12_0_fill_error_record(struct
Quoted 15 lines
---
v2:
- Set ret immediately before the loop instead of initializing it in the declaration, as suggested by Christian.
- Avoid describing the zero-entry case as an allocation-failure fix.drivers/gpu/drm/amd/amdgpu/umc_v12_0.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +0
-0@@ -690,6 +690,7 @@ static int umc_v12_0_fill_error_record(struct
amdgpu_device*adev,Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +1
-1count =amdgpu_umc_lookup_bad_pages_in_a_row (adev, ecc_err->pa_pfn <<AMDGPU_GPU_PAGE_SHIFT , page_pfn,ARRAY_SIZE (page_pfn)); + ret =0 ;for (i =0 ; i < count; i++) { ret = amdgpu_umc_fill_error_record(err_data, --2.51.0
Hi Tao,
Thanks for taking a look.
I will initialize ret to -EINVAL in v3 to keep the behavior aligned with the original logic.
Thanks Christian for the Ack as well.
Thanks,
Ruoyu Wang
Quoted 66 lines · Tao
AMD General
[Tao] In order to align with the original logic, I prefer to "ret =
-EINVAL"Quoted 2 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf OfChristian
Quoted 4 lines
König
Sent: Thursday, June 18, 2026 3:37 PM
To: Ruoyu Wang <[email protected]>; Deucher, Alexander <[email protected]>; David Airlie <[email protected]>; SimonaVetter
Quoted 1 line
Quoted 1 line
[email protected]; Zhang, Hawking <[email protected]>;
Lazar,
Quoted 2 lines
Lijo <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: initialize ret before UMC errorrecord loop
Quoted 9 lines · Ruoyu Wang
Quoted 7 lines
umc_v12_0_fill_error_record()returns ret after walking the pages reported byamdgpu_umc_lookup_bad_pages_in_a_row(). That helper can return zero entries, leaving the loop skipped and ret uninitialized.Set ret to 0 immediately before the loop so the zero-page path reports a deterministic status instead of returning stack data.
Quoted 6 lines
Quoted 2 lines
Suggested-by Christian König <[email protected]>Signed-off-by Ruoyu Wang <[email protected]>Acked-by Christian König <[email protected]>Someone more familiar with ras should take a look as well, could be that
returning -
Quoted 11 lines
ENOENT is more appropriate here.
Quoted 9 lines
---
v2:
- Set ret immediately before the loop instead of initializing it in the declaration, as suggested by Christian.
- Avoid describing the zero-entry case as an allocation-failure fix.drivers/gpu/drm/amd/amdgpu/umc_v12_0.c | 1 + 1 file changed, 1 insertion(+)Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c static int umc_v12_0_fill_error_record(struct
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +0
-0@@ -690,6 +690,7 @@ static int umc_v12_0_fill_error_record(struct
amdgpu_device*adev,Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +0
-0count = amdgpu_umc_lookup_bad_pages_in_a_row(adev, ecc_err->pa_pfn <<
AMDGPU_GPU_PAGE_SHIFT,Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +1
-1page_pfn, ARRAY_SIZE(page_pfn)); + ret =0 ;for (i =0 ; i < count; i++) { ret = amdgpu_umc_fill_error_record(err_data, --2.51.0