drm/amdgpu: read back register after written
Subsystems (2)
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.
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
@@ -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
[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
@@ -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
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 writtenThe addition of register read-back in VCN v1.0 is intended to prevent potential race conditions.
Signed-off-by David (Ming Qiang) Wu<[email protected]>--- 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@@ -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
PATCH 2/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
[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
@@ -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
PATCH 3/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
PATCH 4/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
PATCH 5/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
PATCH 6/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
PATCH 7/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
PATCH 8/8 drm/amdgpu: read back register after written
In reply to David (Ming Qiang) WuThe 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
@@ -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
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
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: