[AMD Official Use Only - AMD Internal Distribution Only] Reviewed-by: Tao Zhou <tao.zh...@amd.com>
> -----Original Message----- > From: Wang, Yang(Kevin) <kevinyang.w...@amd.com> > Sent: Thursday, July 24, 2025 3:39 PM > To: amd-gfx@lists.freedesktop.org > Cc: Zhang, Hawking <hawking.zh...@amd.com>; Zhou1, Tao > <tao.zh...@amd.com> > Subject: [PATCH] drm/amd/amdgpu: fix missing lock for cper.ring->rptr/wptr > access > > Add lock protection for 'ring->wptr'/'ring->rptr' to ensure the correct > execution. > > Fixes: 8652920d2c00 ("drm/amdgpu: add mutex lock for cper ring") > Signed-off-by: Yang Wang <kevinyang.w...@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c > index 15dde1f50328..25252231a68a 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c > @@ -459,7 +459,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 = *ring->rptr_cpu_addr & ring->ptr_mask; > + u64 pos, wptr_old, rptr; > int rec_cnt_dw = count >> 2; > u32 chunk, ent_sz; > u8 *s = (u8 *)src; > @@ -472,9 +472,11 @@ void amdgpu_cper_ring_write(struct amdgpu_ring *ring, > void *src, int count) > return; > } > > + mutex_lock(&ring->adev->cper.ring_lock); > + > wptr_old = ring->wptr; > + rptr = *ring->rptr_cpu_addr & ring->ptr_mask; > > - mutex_lock(&ring->adev->cper.ring_lock); > while (count) { > ent_sz = amdgpu_cper_ring_get_ent_sz(ring, ring->wptr); > chunk = umin(ent_sz, count); > -- > 2.34.1