drm/amd/ras: Fix SMU EEPROM record field decoding
Subsystems (2)
PATCH 1/3 drm/amd/ras: Fix SMU EEPROM record field decoding
The SMU EEPROM read paths pass byte-sized record field addresses to mca_ipid_parse(), whose outputs are u32 pointers.
Writing through those widened pointers can clobber adjacent fields and bytes beyond the record storage.
Parse the IPID values into local u32 temporaries instead, then explicitly narrow the values when storing them in the EEPROM record.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 8 +++++--- drivers/gpu/drm/amd/ras/rascore/ras_eeprom_fw.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +5 -3
@@ -1051,6 +1051,7 @@ int amdgpu_ras_eeprom_read_idx(struct amdgpu_ras_eeprom_control *control,uint64_t ts, end_idx;int i, ret;u64 mca, ipid; +u32 cu, mem_channel, mcumc_id;if (!amdgpu_ras_smu_eeprom_supported (adev))return 0 ;
@@ -1079,9 +1080,10 @@ int amdgpu_ras_eeprom_read_idx(struct amdgpu_ras_eeprom_control *control, record[i - rec_idx].err_type =AMDGPU_RAS_EEPROM_ERR_NON_RECOVERABLE ; adev->umc.ras->mca_ipid_parse (adev, ipid, - (uint32_t *)&(record[i - rec_idx].cu), - (uint32_t *)&(record[i - rec_idx].mem_channel), - (uint32_t *)&(record[i - rec_idx].mcumc_id),NULL ); + &cu, &mem_channel, &mcumc_id,NULL ); + record[i - rec_idx].cu = (u8 )cu; + record[i - rec_idx].mem_channel = (u8 )mem_channel; + record[i - rec_idx].mcumc_id = (u8 )mcumc_id; }return 0 ;
drivers/gpu/drm/amd/ras/rascore/ras_eeprom_fw.c +5 -3
@@ -270,6 +270,7 @@ int ras_fw_eeprom_read_idx(struct ras_core_context *ras_core,struct ras_fw_eeprom_control *control = &ras_core->ras_fw_eeprom;int i, ret, end_idx;u64 mca, ipid, ts; +u32 cu, mem_channel, mcumc_id;if (!ras_core->ras_umc.ip_func || !ras_core->ras_umc.ip_func->mca_ipid_parse)
@@ -299,9 +300,10 @@ int ras_fw_eeprom_read_idx(struct ras_core_context *ras_core, record_umc[i - rec_idx].err_type =RAS_EEPROM_ERR_NON_RECOVERABLE ; ras_core->ras_umc.ip_func->mca_ipid_parse (ras_core, ipid, - (uint32_t *)&(record_umc[i - rec_idx].cu), - (uint32_t *)&(record_umc[i - rec_idx].mem_channel), - (uint32_t *)&(record_umc[i - rec_idx].mcumc_id),NULL ); + &cu, &mem_channel, &mcumc_id,NULL ); + record_umc[i - rec_idx].cu = (u8 )cu; + record_umc[i - rec_idx].mem_channel = (u8 )mem_channel; + record_umc[i - rec_idx].mcumc_id = (u8 )mcumc_id;/* update bad channel bitmap */ if ((record_umc[i - rec_idx].mem_channel < BITS_PER_TYPE(control->bad_channel_bitmap)) &&
Signature · 1 line
2.54.0
PATCH 2/3 drm/amd/ras: reset CPER ring on corrupt entry size
When CPER ring overflow handling advances the read pointer, it trusts the parsed entry size from the current ring contents. Corrupt CPER data can produce an entry size that does not advance rptr after dword conversion and pointer masking.
In that case the recovery loop keeps testing the same location while holding the CPER ring mutex. This can hang the worker that is writing the next CPER record.
Detect a no-progress rptr update and reset the CPER ring to an empty state instead. This drops the corrupt contents and lets the writer leave the recovery path without spinning.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c +16 -4
@@ -484,7 +484,7 @@ static u32 amdgpu_cper_ring_get_ent_sz(struct amdgpu_ring *ring, u64 pos)void amdgpu_cper_ring_write (struct amdgpu_ring *ring,void *src,int count) { -u64 pos, wptr_old, rptr; +u64 pos, wptr_old, rptr, next_rptr;int rec_cnt_dw = count >>2 ;u32 chunk, ent_sz;u8 *s = (u8 *)src;
@@ -525,9 +525,19 @@ void amdgpu_cper_ring_write(struct amdgpu_ring *ring, void *src, int count) do { ent_sz = amdgpu_cper_ring_get_ent_sz(ring, pos); - - rptr += (ent_sz >> 2); - rptr &= ring->ptr_mask; + next_rptr = rptr; + if (ent_sz >= sizeof(u32)) + next_rptr = (rptr + (ent_sz >> 2)) & ring->ptr_mask; + + if (next_rptr == rptr) { + /* Corrupt entry size, reset the ring to avoid an infinite loop. */ + rptr = ring->wptr; + *ring->rptr_cpu_addr = rptr; + ring->count_dw = (ring->ring_size - 4) >> 2; + goto out_unlock; + } + + rptr = next_rptr; *ring->rptr_cpu_addr = rptr; pos = rptr;
@@ -536,6 +546,8 @@ void amdgpu_cper_ring_write(struct amdgpu_ring *ring, void *src, int count)if (ring->count_dw >= rec_cnt_dw) ring->count_dw -= rec_cnt_dw; + +out_unlock:mutex_unlock (&ring->adev->cper.ring_lock); }
Signature · 1 line
2.54.0
PATCH 3/3 drm/amd/ras: Fix UMC error address allocation leak
In reply to Xiang Liuamdgpu_umc_handle_bad_pages() allocates err_data->err_addr before querying UMC error information. In the direct and firmware query paths, the pointer is reassigned to a fresh allocation before the original buffer is released, so the initial allocation is leaked on each handled event.
Free the existing buffer before replacing it in those query paths so the function exit cleanup only owns the active allocation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -0
@@ -130,6 +130,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops && adev->umc.ras->ras_block.hw_ops->query_ras_error_address && adev->umc.max_ras_err_cnt_per_query) { +kfree (err_data->err_addr); err_data->err_addr =kcalloc (adev->umc.max_ras_err_cnt_per_query,sizeof (struct eeprom_table_record ),GFP_KERNEL );
@@ -160,6 +161,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,if (adev->umc.ras && adev->umc.ras->ecc_info_query_ras_error_address && adev->umc.max_ras_err_cnt_per_query) { +kfree (err_data->err_addr); err_data->err_addr =kcalloc (adev->umc.max_ras_err_cnt_per_query,sizeof (struct eeprom_table_record ),GFP_KERNEL );
Signature · 1 line
2.54.0
RE: [PATCH 3/3] drm/amd/ras: Fix UMC error address allocation leak
AMD General
The series is: Reviewed-by: Tao Zhou <[email protected]>
Quoted 53 lines
-----Original Message-----
From: Liu, Xiang(Dean) <[email protected]>
Sent: Monday, May 18, 2026 2:51 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>; Liu, Xiang(Dean) <[email protected]>
Subject: [PATCH 3/3] drm/amd/ras: Fix UMC error address allocation leak
amdgpu_umc_handle_bad_pages()allocateserr_data->err_addrbefore querying UMC error information. In the direct and firmware query paths, the pointer is reassigned to a fresh allocation before the original buffer is released, so the initial allocation is leaked on each handled event.Free the existing buffer before replacing it in those query paths so the function exit cleanup only owns the active allocation.
Signed-off-by Xiang Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0
-0@@ -130,6 +130,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev, if (adev->umc.ras && adev->umc.ras-Quoted 1 line
ras_block.hw_ops &&
adev->umc.ras->ras_block.hw_ops-Quoted 1 line
query_ras_error_address&&adev->umc.max_ras_err_cnt_per_query) { + kfree(err_data->err_addr); err_data->err_addr = kcalloc(adev-Quoted 1 line
umc.max_ras_err_cnt_per_query,
sizeof(struct
eeprom_table_record),GFP_KERNEL); @@ -160,6 +161,7 @@ void amdgpu_umc_handle_bad_pages(structamdgpu_device*adev,if (adev->umc.ras && adev->umc.ras->ecc_info_query_ras_error_address && adev->umc.max_ras_err_cnt_per_query) { + kfree(err_data->err_addr); err_data->err_addr = kcalloc(adev-Quoted 1 line
umc.max_ras_err_cnt_per_query,
sizeof(struct
eeprom_table_record),GFP_KERNEL);
--
2.54.0
RE: [PATCH 3/3] drm/amd/ras: Fix UMC error address allocation leak
In reply to Xiang LiuAMD General
The series is Reviewed-by: Stanley.Yang <[email protected]>
Regards,
Stanley
Quoted 53 lines
-----Original Message-----
From: Liu, Xiang(Dean) <[email protected]>
Sent: Monday, May 18, 2026 2:51 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>; Liu, Xiang(Dean) <[email protected]>
Subject: [PATCH 3/3] drm/amd/ras: Fix UMC error address allocation leak
amdgpu_umc_handle_bad_pages()allocateserr_data->err_addrbefore querying UMC error information. In the direct and firmware query paths, the pointer is reassigned to a fresh allocation before the original buffer is released, so the initial allocation is leaked on each handled event.Free the existing buffer before replacing it in those query paths so the function exit cleanup only owns the active allocation.
Signed-off-by Xiang Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0
-0@@ -130,6 +130,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev, if (adev->umc.ras && adev->umc.ras-Quoted 1 line
ras_block.hw_ops &&
adev->umc.ras->ras_block.hw_ops-Quoted 1 line
query_ras_error_address&&adev->umc.max_ras_err_cnt_per_query) { + kfree(err_data->err_addr); err_data->err_addr = kcalloc(adev-Quoted 1 line
umc.max_ras_err_cnt_per_query,
sizeof(struct
eeprom_table_record),GFP_KERNEL); @@ -160,6 +161,7 @@ void amdgpu_umc_handle_bad_pages(structamdgpu_device*adev,if (adev->umc.ras && adev->umc.ras->ecc_info_query_ras_error_address && adev->umc.max_ras_err_cnt_per_query) { + kfree(err_data->err_addr); err_data->err_addr = kcalloc(adev-Quoted 1 line
umc.max_ras_err_cnt_per_query,
sizeof(struct
eeprom_table_record),GFP_KERNEL);
--
2.54.0