]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: handle wrap around in reemit handling
authorAlex Deucher <alexander.deucher@amd.com>
Mon, 15 Sep 2025 16:37:32 +0000 (12:37 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 13 Oct 2025 18:14:15 +0000 (14:14 -0400)
Compare the sequence numbers directly.

Fixes: 77cc0da39c7c ("drm/amdgpu: track ring state associated with a fence")
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c

index fd8cca241da6267f0c0d20fff11c3428ef1a9323..e270df30c27907c301e2512f958ab5c0c43c4146 100644 (file)
@@ -790,14 +790,19 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
        struct dma_fence *unprocessed;
        struct dma_fence __rcu **ptr;
        struct amdgpu_fence *fence;
-       u64 wptr, i, seqno;
+       u64 wptr;
+       u32 seq, last_seq;
 
-       seqno = amdgpu_fence_read(ring);
+       last_seq = amdgpu_fence_read(ring) & ring->fence_drv.num_fences_mask;
+       seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask;
        wptr = ring->fence_drv.signalled_wptr;
        ring->ring_backup_entries_to_copy = 0;
 
-       for (i = seqno + 1; i <= ring->fence_drv.sync_seq; ++i) {
-               ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask];
+       do {
+               last_seq++;
+               last_seq &= ring->fence_drv.num_fences_mask;
+
+               ptr = &ring->fence_drv.fences[last_seq];
                rcu_read_lock();
                unprocessed = rcu_dereference(*ptr);
 
@@ -813,7 +818,7 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
                        wptr = fence->wptr;
                }
                rcu_read_unlock();
-       }
+       } while (last_seq != seq);
 }
 
 /*