drm/amdgpu: Use READ_ONCE() when reading the values in 'sdma_v4_4_2_ring_get_rptr'
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Fri, 4 Aug 2023 05:46:41 +0000 (11:16 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 30 Aug 2023 19:51:17 +0000 (15:51 -0400)
Use READ_ONCE() instead of declaring the pointer volatile. To prevent
the compiler from refetching or reordering the read, so that the read
value is always consistent.

Link: https://lwn.net/Articles/624126/
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Guchun Chen <guchun.chen@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Cc: Le Ma <le.ma@amd.com>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Le Ma <le.ma@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index f413898dda37dbe75788f3b69db22f968c7d484f..267c1b7b8dcdf181a5db4372fd258a36717b72da 100644 (file)
@@ -154,13 +154,13 @@ static int sdma_v4_4_2_init_microcode(struct amdgpu_device *adev)
  */
 static uint64_t sdma_v4_4_2_ring_get_rptr(struct amdgpu_ring *ring)
 {
-       u64 *rptr;
+       u64 rptr;
 
        /* XXX check if swapping is necessary on BE */
-       rptr = ((u64 *)&ring->adev->wb.wb[ring->rptr_offs]);
+       rptr = READ_ONCE(*((u64 *)&ring->adev->wb.wb[ring->rptr_offs]));
 
-       DRM_DEBUG("rptr before shift == 0x%016llx\n", *rptr);
-       return ((*rptr) >> 2);
+       DRM_DEBUG("rptr before shift == 0x%016llx\n", rptr);
+       return rptr >> 2;
 }
 
 /**