]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/amdgpu: fix missing lock for cper.ring->rptr/wptr access
authorYang Wang <kevinyang.wang@amd.com>
Thu, 24 Jul 2025 07:16:18 +0000 (15:16 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 28 Jul 2025 20:26:52 +0000 (16:26 -0400)
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.wang@amd.com>
Reviewed-by: Tao Zhou <tao.zhou1@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/amdgpu_cper.c

index 15dde1f5032842420c7cbcfc30fed212fc20b022..25252231a68a946b3fc5e2ed76c92cd5536311e1 100644 (file)
@@ -459,7 +459,7 @@ calc:
 
 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);