Skip to contentSkip to conversation

drm/amdgpu: read back register after written

PATCH Superseded David (Ming Qiang) Wu 4 participants 14 messages May 14, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover drm/amdgpu: read back register after written

Similar to the changes made for VCN v4.0.5, the addition of register read-back support in other VCN versions is intended to prevent potential race conditions, even though such issues have not been observed yet. This change ensures consistency across different VCN variants and helps avoid similar issues. The overhead introduced is negligible.

#1 lore raw

PATCH 1/8 drm/amdgpu: read back register after written

The addition of register read-back in VCN v1.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +10 -0
index 21b57c29bf7d..f56b623713c9 100644
@@ -1009,6 +1009,11 @@ static int vcn_v1_0_start_spg_mode(struct amdgpu_vcn_inst *vinst)
 
 	jpeg_v1_0_start(adev, 0);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
@@ -1154,6 +1159,11 @@ static int vcn_v1_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst)
 
 	jpeg_v1_0_start(adev, 1);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

This patch is not needed as it has the read-back in jpeg_v1_0_start();

Thanks,
Ruijing

-----Original Message-----
From: Wu, David <[email protected]>
Sent: Wednesday, May 14, 2025 1:23 PM
To: [email protected]; Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; Liu, Leo <[email protected]>; Jiang, Sonny <[email protected]>; Dong, Ruijing <[email protected]>
Subject: [PATCH v1 1/8] drm/amdgpu: read back register after written

The addition of register read-back in VCN v1.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +10 -0
index 21b57c29bf7d..f56b623713c9 100644
@@ -1009,6 +1009,11 @@ static int vcn_v1_0_start_spg_mode(struct amdgpu_vcn_inst *vinst)
 
        jpeg_v1_0_start(adev, 0);
 
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
        return 0;
 }
 
@@ -1154,6 +1159,11 @@ static int vcn_v1_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst)
 
        jpeg_v1_0_start(adev, 1);
 
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
        return 0;
 }
 

--
2.49.0

#3 lore raw

hmm... I knew that - but I would rather add that in case jpeg_v1_0_start() might change. A little conservative ...

Thanks,
David

Quoted 52 lines · Ruijing

[AMD Official Use Only - AMD Internal Distribution Only]

This patch is not needed as it has the read-back in jpeg_v1_0_start();

Thanks,
Ruijing

-----Original Message-----
From: Wu, David<[email protected]>
Sent: Wednesday, May 14, 2025 1:23 PM
To:[email protected]; Deucher, Alexander<[email protected]>
Cc: Koenig, Christian<[email protected]>; Liu, Leo<[email protected]>; Jiang, Sonny<[email protected]>; Dong, Ruijing<[email protected]>
Subject: [PATCH v1 1/8] drm/amdgpu: read back register after written

The addition of register read-back in VCN v1.0 is intended to prevent potential race conditions.

---
  drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +10 -1
index 21b57c29bf7d..f56b623713c9 100644
@@ -1009,6 +1009,11 @@ static int vcn_v1_0_start_spg_mode(struct amdgpu_vcn_inst *vinst)
 
         jpeg_v1_0_start(adev, 0);
 
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
         return 0;
  }
 
@@ -1154,6 +1159,11 @@ static int vcn_v1_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst)
 
         jpeg_v1_0_start(adev, 1);
 
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
         return 0;
  }
 
--

2.49.0

#4 lore raw

PATCH 2/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v2.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +11 -0
index b8d835c9e17e..e6a008d7e67c 100644
@@ -978,6 +978,12 @@ static int vcn_v2_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst, bool indirect)
 	/* Unstall DPG */
 	WREG32_P(SOC15_REG_OFFSET(UVD, 0, mmUVD_POWER_STATUS),
 		0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);
+
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
@@ -1152,6 +1158,11 @@ static int vcn_v2_0_start(struct amdgpu_vcn_inst *vinst)
 	WREG32_SOC15(UVD, 0, mmUVD_RB_SIZE2, ring->ring_size / 4);
 	fw_shared->multi_queue.encode_lowlatency_queue_mode &= ~FW_QUEUE_RING_RESET;
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#5 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Only in start() ? what about stop(), pause() and etc?

Thanks,
Ruijing

-----Original Message-----
From: Wu, David <[email protected]>
Sent: Wednesday, May 14, 2025 1:23 PM
To: [email protected]; Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; Liu, Leo <[email protected]>; Jiang, Sonny <[email protected]>; Dong, Ruijing <[email protected]>
Subject: [PATCH v1 2/8] drm/amdgpu: read back register after written

The addition of register read-back in VCN v2.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +11 -0
index b8d835c9e17e..e6a008d7e67c 100644
@@ -978,6 +978,12 @@ static int vcn_v2_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst, bool indirect)
        /* Unstall DPG */
        WREG32_P(SOC15_REG_OFFSET(UVD, 0, mmUVD_POWER_STATUS),
                0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);
+
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
        return 0;
 }
 
@@ -1152,6 +1158,11 @@ static int vcn_v2_0_start(struct amdgpu_vcn_inst *vinst)
        WREG32_SOC15(UVD, 0, mmUVD_RB_SIZE2, ring->ring_size / 4);
        fw_shared->multi_queue.encode_lowlatency_queue_mode &= ~FW_QUEUE_RING_RESET;
 
+       /* Keeping one read-back to ensure all register writes are done, otherwise
+        * it may introduce race conditions
+        */
+       RREG32_SOC15(UVD, 0, mmUVD_RBC_RB_WPTR);
+
        return 0;
 }
 

--
2.49.0

#6 lore raw

PATCH 3/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v2.5 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +10 -0
index 3eec1b8feaee..beffe0795ca9 100644
@@ -1158,6 +1158,11 @@ static int vcn_v2_5_start_dpg_mode(struct amdgpu_vcn_inst *vinst, bool indirect)
 	WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, mmUVD_POWER_STATUS),
 		0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(VCN, inst_idx, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
@@ -1343,6 +1348,11 @@ static int vcn_v2_5_start(struct amdgpu_vcn_inst *vinst)
 	WREG32_SOC15(VCN, i, mmUVD_RB_SIZE2, ring->ring_size / 4);
 	fw_shared->multi_queue.encode_lowlatency_queue_mode &= ~FW_QUEUE_RING_RESET;
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(VCN, i, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#7 lore raw

PATCH 4/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v3.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +10 -0
index 0b19f0ab4480..792edc6582c1 100644
@@ -1173,6 +1173,11 @@ static int vcn_v3_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst, bool indirect)
 	WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, mmUVD_POWER_STATUS),
 		0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(VCN, inst_idx, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
@@ -1360,6 +1365,11 @@ static int vcn_v3_0_start(struct amdgpu_vcn_inst *vinst)
 		fw_shared->multi_queue.encode_lowlatency_queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET);
 	}
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions
+	 */
+	RREG32_SOC15(VCN, i, mmUVD_RBC_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#8 lore raw

PATCH 5/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v4.0.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +10 -0
index 8fff470bce87..d3c5c30f35bb 100644
@@ -1122,6 +1122,11 @@ static int vcn_v4_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst, bool indirect)
 			ring->doorbell_index << VCN_RB1_DB_CTRL__OFFSET__SHIFT |
 			VCN_RB1_DB_CTRL__EN_MASK);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR);
+
 	return 0;
 }
 
@@ -1303,6 +1308,11 @@ static int vcn_v4_0_start(struct amdgpu_vcn_inst *vinst)
 	WREG32_SOC15(VCN, i, regVCN_RB_ENABLE, tmp);
 	fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, i, regUVD_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#9 lore raw

PATCH 6/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v4.0.3 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +4 -0
index 712e1fba33ce..9729eb1fbc6c 100644
@@ -970,6 +970,10 @@ static int vcn_v4_0_3_start_dpg_mode(struct amdgpu_vcn_inst *vinst,
 	/*resetting done, fw can check RB ring */
 	fw_shared->sq.queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE);
 	return 0;
 }
 
Signature · 1 line
2.49.0
#10 lore raw

PATCH 7/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v5.0.0 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +10 -0
index 27dcc6f37a73..bf2bd60415f9 100644
@@ -794,6 +794,11 @@ static int vcn_v5_0_0_start_dpg_mode(struct amdgpu_vcn_inst *vinst,
 		ring->doorbell_index << VCN_RB1_DB_CTRL__OFFSET__SHIFT |
 		VCN_RB1_DB_CTRL__EN_MASK);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, inst_idx, regUVD_RB_WPTR);
+
 	return 0;
 }
 
@@ -946,6 +951,11 @@ static int vcn_v5_0_0_start(struct amdgpu_vcn_inst *vinst)
 	WREG32_SOC15(VCN, i, regVCN_RB_ENABLE, tmp);
 	fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, i, regUVD_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#11 lore raw

PATCH 8/8 drm/amdgpu: read back register after written

In reply to David (Ming Qiang) Wu

The addition of register read-back in VCN v5.0.1 is intended to prevent potential race conditions.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +5 -0
index 60ee6e02e6ac..edf6d29dccb6 100644
@@ -809,6 +809,11 @@ static int vcn_v5_0_1_start(struct amdgpu_vcn_inst *vinst)
 	WREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE, tmp);
 	fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF);
 
+	/* Keeping one read-back to ensure all register writes are done, otherwise
+	 * it may introduce race conditions.
+	 */
+	RREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR);
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#12 lore raw
In reply to David (Ming Qiang) Wu
Quoted 7 lines · David (Ming Qiang) Wu

Similar to the changes made for VCN v4.0.5, the addition of register read-back support in other VCN versions is intended to prevent potential race conditions, even though such issues have not been observed yet. This change ensures consistency across different VCN variants and helps avoid similar issues. The overhead introduced is negligible.

Just for some background this is standard PCI MMIO behavior. If you want to guarantee that the writes hit the hardware, you need to do a read to post the writes. You only need to do it for cases where you care about the writes posting before the next operation.

Alex

Reviewed-by on the v1 series
#13 lore raw
In reply to David (Ming Qiang) Wu
Quoted 7 lines · David (Ming Qiang) Wu

Similar to the changes made for VCN v4.0.5, the addition of register read-back support in other VCN versions is intended to prevent potential race conditions, even though such issues have not been observed yet. This change ensures consistency across different VCN variants and helps avoid similar issues. The overhead introduced is negligible.

May want to update the comments to say something like:

/* read back to post the writes so we don't race with the doorbell */

Either way, the series is: