Skip to contentSkip to conversation

drm/amdgpu/gfx10: fix wptr reset in KGQ init

PATCH In review Alex Deucher 5 participants 10 messages Jan 29 – Jan 30

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/3 drm/amdgpu/gfx10: fix wptr reset in KGQ init

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index e9254ec3b6417..ef7d91a4437ec 100644
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
 			memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
 		/* reset the ring */
 		ring->wptr = 0;
-		*ring->wptr_cpu_addr = 0;
+		atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
 		amdgpu_ring_clear_ring(ring);
 	}
 
Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH 2/3 drm/amdgpu/gfx11: fix wptr reset in KGQ init

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 6145cfc0334b2..b5a2d09fc3469 100644
@@ -4224,7 +4224,7 @@ static int gfx_v11_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
 			memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
 		/* reset the ring */
 		ring->wptr = 0;
-		*ring->wptr_cpu_addr = 0;
+		atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
 		amdgpu_ring_clear_ring(ring);
 	}
 
Signature · 1 line
2.52.0
author maintainer
#2 lore raw

PATCH 3/3 drm/amdgpu/gfx12: fix wptr reset in KGQ init

In reply to Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -1
index 9e48045b036a4..d8ab93c82366d 100644
@@ -3096,7 +3096,7 @@ static int gfx_v12_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
 			memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
 		/* reset the ring */
 		ring->wptr = 0;
-		*ring->wptr_cpu_addr = 0;
+		atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
 		amdgpu_ring_clear_ring(ring);
 	}
 
Signature · 1 line
2.52.0
Reviewed-by on v1 3/3
#3 lore raw

RE: [PATCH 3/3] drm/amdgpu/gfx12: fix wptr reset in KGQ init

[AMD Official Use Only - AMD Internal Distribution Only]

Series is :

Quoted 34 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Thursday, January 29, 2026 12:35 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 3/3] drm/amdgpu/gfx12: fix wptr reset in KGQ init

wptr is a 64 bit value and we need to update the full value, not just 32 bits. Align with what we already do for KCQs.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -1
index 9e48045b036a4..d8ab93c82366d 100644
@@ -3096,7 +3096,7 @@ static int gfx_v12_0_kgq_init_queue(struct amdgpu_ring
 *ring, bool reset)
                      memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx],
 sizeof(*mqd));
              /* reset the ring */
              ring->wptr = 0;
-             *ring->wptr_cpu_addr = 0;
+             atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
              amdgpu_ring_clear_ring(ring);
      }

--
2.52.0

Reviewed-by on v1 1/3
#4 lore raw
In reply to Alex Deucher
Quoted 5 lines · Central European Standard Time Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

for the series.

I notice that the code base already does this for gfx9, but is rather inconsistent on gfx6-8. If you think that's useful, I could submit some patches to do the same on older GPUs. What do you think?

Quoted 17 lines
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c index e9254ec3b6417..ef7d91a4437ec 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring
 *ring, bool reset) memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx],

sizeof(*mqd)); /* reset the ring */

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
 		ring->wptr = 0;
-		*ring->wptr_cpu_addr = 0;
+		atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
 		amdgpu_ring_clear_ring(ring);
 	}
#5 lore raw
Quoted 7 lines · Timur Kristóf
Quoted 4 lines · Central European Standard Time Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

Quoted 8 lines
Quoted 1 line

for the series.

I notice that the code base already does this for gfx9, but is rather inconsistent on gfx6-8. If you think that's useful, I could submit some patches to do the same on older GPUs. What do you think?

Thanks. Pre-gfx9 only had a 32 bit wptr so they don't use the upper 32 bits.

Alex

Quoted 22 lines
Quoted 18 lines
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c index e9254ec3b6417..ef7d91a4437ec 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring
 *ring, bool reset) memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx],

sizeof(*mqd)); /* reset the ring */

              ring->wptr = 0;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
-             *ring->wptr_cpu_addr = 0;
+             atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
              amdgpu_ring_clear_ring(ring);
      }
#6 lore raw
In reply to Alex Deucher
Quoted 14 lines · Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index e9254ec3b6417..ef7d91a4437ec 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset) · line 6886

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
  			memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
  		/* reset the ring */
  		ring->wptr = 0;
-		*ring->wptr_cpu_addr = 0;
+		atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);

For my education could I ask if this just about writing the 64-bit value or the atomic part is also important?

Regards,

Tvrtko

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
  		amdgpu_ring_clear_ring(ring);
  	}
 
#7 lore raw
Quoted 12 lines · Tvrtko Ursulin
Quoted 9 lines · Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset) · line 6886

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index e9254ec3b6417..ef7d91a4437ec 100644
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
                      memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
              /* reset the ring */
              ring->wptr = 0;
-             *ring->wptr_cpu_addr = 0;
+             atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);

For my education could I ask if this just about writing the 64-bit value or the atomic part is also important?

Just the 64 bit value in this case.

Alex

Quoted 9 lines

Regards,

Tvrtko

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
              amdgpu_ring_clear_ring(ring);
      }
 
#8 lore raw
Quoted 27 lines · Alex Deucher
Quoted 12 lines · Tvrtko Ursulin
Quoted 9 lines · Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
   drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset) · line 6886

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index e9254ec3b6417..ef7d91a4437ec 100644
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
                       memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
               /* reset the ring */
               ring->wptr = 0;
-             *ring->wptr_cpu_addr = 0;
+             atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);

For my education could I ask if this just about writing the 64-bit value or the atomic part is also important?

Quoted 1 line

Just the 64 bit value in this case.

Thank you, it was a bit confusing for me. Even in the context of what you explained to Timur that pre-gfx9 wptr is 32-bit, becauase when I looked into for example the gfx8 code, I saw it doing a mix of 64- and 32-bit writes.

I guess the layout of the write back info block thingy is fully software/driver defined which is why this is not an issue?

Would it be worth getting rid of the atomics to lessen the confusion and attempt to somehow make this area more self-documenting?

Regards,

Tvrtko

#9 lore raw
Quoted 32 lines · Tvrtko Ursulin
Quoted 27 lines · Alex Deucher
Quoted 12 lines · Tvrtko Ursulin
Quoted 9 lines · Alex Deucher

wptr is a 64 bit value and we need to update the
full value, not just 32 bits. Align with what we
already do for KCQs.

---
   drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset) · line 6886

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index e9254ec3b6417..ef7d91a4437ec 100644
@@ -6883,7 +6883,7 @@ static int gfx_v10_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
                       memcpy_toio(mqd, adev->gfx.me.mqd_backup[mqd_idx], sizeof(*mqd));
               /* reset the ring */
               ring->wptr = 0;
-             *ring->wptr_cpu_addr = 0;
+             atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);

For my education could I ask if this just about writing the 64-bit value or the atomic part is also important?

Quoted 1 line

Just the 64 bit value in this case.

Quoted 7 lines

Thank you, it was a bit confusing for me. Even in the context of what you explained to Timur that pre-gfx9 wptr is 32-bit, becauase when I looked into for example the gfx8 code, I saw it doing a mix of 64- and 32-bit writes.

I guess the layout of the write back info block thingy is fully software/driver defined which is why this is not an issue?

The buffer is 64 bits because we support a mix of GPUs, some of which support 64 bit write pointers and some of which support 32 bit write pointers, even on the same GPU (e.g., different IPs may have different sizes).

Quoted 3 lines

Would it be worth getting rid of the atomics to lessen the confusion and attempt to somehow make this area more self-documenting?

Yeah, I suspect the 64 bit updates came back to the older IPs as part of code unification and cleanups from newer chips. Each ring has a ptr_mask in its ring data structure which defines its write pointer size.

Alex

Quoted 4 lines

Regards,

Tvrtko