Skip to contentSkip to conversation

drm/amdgpu: read back register after written for VCN v4.0.5

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

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amdgpu: read back register after written for VCN v4.0.5

V2: not to add extra read-back in vcn_v4_0_5_start as there is a
read-back already. New comment for better understanding.

On VCN v4.0.5 there is a race condition where the WPTR is not updated after starting from idle when doorbell is used. The read-back of regVCN_RB1_DB_CTRL register after written is to ensure the doorbell_index is updated before it can work properly.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +4 -0
index ed00d35039c13..e55b76d71367d 100644
@@ -1034,6 +1034,10 @@ static int vcn_v4_0_5_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, regVCN_RB1_DB_CTRL);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -0
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
Reviewed-by Mario Limonciello on v2 2/2
#2 lore raw

RE: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

[AMD Official Use Only - AMD Internal Distribution Only]

Hi David,

The last register operation in vcn_v4_0_start and vcn_v5_0_0_start is write, I guess we can extend this little more to do a dummy read as the last register operation.

Thanks,
Ruijing

-----Original Message-----
From: Wu, David <[email protected]>
Sent: Tuesday, May 13, 2025 2:23 PM
To: [email protected]; Koenig, Christian <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Liu, Leo <[email protected]>; Jiang, Sonny <[email protected]>; Dong, Ruijing <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -0
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 

--
2.34.1

#3 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

In reply to David (Ming Qiang) Wu
Quoted 11 lines · David (Ming Qiang) Wu

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Quoted 2 lines

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

Alex

Quoted 38 lines
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
--

2.34.1

#4 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

Quoted 11 lines · Alex Deucher
Quoted 10 lines · David (Ming Qiang) Wu

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Quoted 5 lines
Quoted 2 lines

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

will split.

This applies to those VCNs where regVCN_RB1_DB_CRTL is used for setting doorbell index, which

means VCN 4 and up - all of them are covered (similar code is already there for those not in this patch).

David

Quoted 41 lines

Alex

Quoted 38 lines
---
  drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
  drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
  2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
--

2.34.1

#5 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

Quoted 23 lines · David Wu

On 2025-05-13 14:40, Alex Deucher wrote:

On Tue, May 13, 2025 at 2:23 PM David (Ming Qiang) Wu <[email protected]> wrote:

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

Quoted 5 lines

will split.

This applies to those VCNs where regVCN_RB1_DB_CRTL is used for setting doorbell index, which

means VCN 4 and up - all of them are covered (similar code is already there for those not in this patch).

Sure that prevents the doorbell from getting missed, but what about other registers setup in the VCN start() functions? What if some of those are still pending when the doorbell is rung for other VCNs?

Alex

Quoted 43 lines

David

Alex

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
 2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
--

2.34.1

#6 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

Quoted 23 lines · Alex Deucher
Quoted 22 lines · David Wu

On 2025-05-13 14:40, Alex Deucher wrote:

On Tue, May 13, 2025 at 2:23 PM David (Ming Qiang) Wu <[email protected]> wrote:

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

Quoted 8 lines
Quoted 5 lines

will split.

This applies to those VCNs where regVCN_RB1_DB_CRTL is used for setting doorbell index, which

means VCN 4 and up - all of them are covered (similar code is already there for those not in this patch).

Sure that prevents the doorbell from getting missed, but what about other registers setup in the VCN start() functions? What if some of those are still pending when the doorbell is rung for other VCNs?

I think adding a read-back is needed if there is any concern about race condition.
If we only concern about start() it should be easy to add. The question is how we will know there is a race condition. Adding read back everywhere when missing after write is not a solution I think. For any VCN functions we need to check carefully (eg. vcn_v4_0_unified_ring_set_wptr()) in case it adds too much overhead and actually not needed (at least haven't seen the issue).
Any suggestion as to where we should add or at the moment for _start()? I can work on it for sure or leave it for future improvement.

David

Quoted 45 lines

Alex

Quoted 42 lines

David

Alex

---
  drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
  drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
  2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
--

2.34.1

#7 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

Quoted 34 lines · David Wu
Quoted 23 lines · Alex Deucher
Quoted 22 lines · David Wu

On 2025-05-13 14:40, Alex Deucher wrote:

On Tue, May 13, 2025 at 2:23 PM David (Ming Qiang) Wu <[email protected]> wrote:

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

Quoted 8 lines
Quoted 5 lines

will split.

This applies to those VCNs where regVCN_RB1_DB_CRTL is used for setting doorbell index, which

means VCN 4 and up - all of them are covered (similar code is already there for those not in this patch).

Sure that prevents the doorbell from getting missed, but what about other registers setup in the VCN start() functions? What if some of those are still pending when the doorbell is rung for other VCNs?

Quoted 12 lines

I think adding a read-back is needed if there is any concern about race condition.
If we only concern about start() it should be easy to add. The question is how we will know there is
a race condition. Adding read back everywhere when missing after write is not a solution I think.
For any VCN functions we need to check carefully
(eg. vcn_v4_0_unified_ring_set_wptr()) in case it adds too much overhead and actually not needed (at least haven't seen the issue). Any suggestion as to where we should add or at the moment for _start()? I can work on it for sure or leave it for
future improvement.

I think _start() makes the most sense because it will only be called when we power on the VCN instance. As long as work keeps coming in, it will stay on. The race is theoretically possible on any VCN instance. E.g., when the first VCN job comes in, VCN gets powered on, and then we call _start() to program what we need. After that, we ring the doorbell to kick off the job. The programming sequence in _start() could still be in flight on the PCIe bus when the doorbell gets rung. Which is apparently exactly what happens when we hit this issue on VCN 4.x and 5.x. On VCN the doorbell gets ignored because it races with the doorbell id register, but on other VCNs, the doorbell getting missed may not happen, but it could be something else that races, e.g., ring size.

Alex

Quoted 48 lines

David

Quoted 45 lines

Alex

Quoted 42 lines

David

Alex

---
  drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
  drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
  2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
         return 0;
  }
 
--

2.34.1

#8 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: read back register after written for VCN v4.0.0 and v5.0.0

Quoted 45 lines · Alex Deucher
Quoted 32 lines · David Wu
Quoted 22 lines · Alex Deucher
Quoted 21 lines · David Wu

On 2025-05-13 14:40, Alex Deucher wrote:

On Tue, May 13, 2025 at 2:23 PM David (Ming Qiang) Wu <[email protected]> wrote:

V2: not to add extra read-back in vcn_v4_0_start and vcn_v5_0_0_start as
there are read-back calls already. New comments for better understanding.

Similar to the previous changes made for VCN v4.0.5, the addition of register read-back support in VCN v4.0.0 and v5.0.0 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 on newer or closely related GPUs. The overhead introduced by this read-back is negligible.

Maybe split this into two patches, one for vcn 4 and one for vcn 5. That will make it easier to backport to stable. What about other VCNs?

Quoted 8 lines
Quoted 5 lines

will split.

This applies to those VCNs where regVCN_RB1_DB_CRTL is used for setting doorbell index, which

means VCN 4 and up - all of them are covered (similar code is already there for those not in this patch).

Sure that prevents the doorbell from getting missed, but what about other registers setup in the VCN start() functions? What if some of those are still pending when the doorbell is rung for other VCNs?

Quoted 12 lines

I think adding a read-back is needed if there is any concern about race condition.
If we only concern about start() it should be easy to add. The question is how we will know there is
a race condition. Adding read back everywhere when missing after write is not a solution I think.
For any VCN functions we need to check carefully
(eg. vcn_v4_0_unified_ring_set_wptr()) in case it adds too much overhead and actually not needed (at least haven't seen the issue). Any suggestion as to where we should add or at the moment for _start()? I can work on it for sure or leave it for
future improvement.

Quoted 12 lines

I think _start() makes the most sense because it will only be called when we power on the VCN instance. As long as work keeps coming in, it will stay on. The race is theoretically possible on any VCN instance. E.g., when the first VCN job comes in, VCN gets powered on, and then we call _start() to program what we need. After that, we ring the doorbell to kick off the job. The programming sequence in _start() could still be in flight on the PCIe bus when the doorbell gets rung. Which is apparently exactly what happens when we hit this issue on VCN 4.x and 5.x. On VCN the doorbell gets ignored because it races with the doorbell id register, but on other VCNs, the doorbell getting missed may not happen, but it could be something else that races, e.g., ring size.

well - right. For production we enable DPG which is now protected. the other register write at the end of _start() is for non-DPG case. I can add read-back there just in case.
I guess for other issues/potential race conditions we need to investigate case by case. Sounds OK?

David

Quoted 49 lines

Alex

Quoted 46 lines

David

Quoted 44 lines

Alex

Quoted 42 lines

David

Alex

---
   drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 4 ++++
   drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 4 ++++
   2 files changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +4 -0
index 8fff470bce873..070a2a8cdf6f4 100644
@@ -1122,6 +1122,10 @@ 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, regVCN_RB1_DB_CTRL);
+
          return 0;
   }
 
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +4 -1
index 27dcc6f37a730..77c27a317e4c8 100644
@@ -794,6 +794,10 @@ 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, regVCN_RB1_DB_CTRL);
+
          return 0;
   }
 
--

2.34.1

Reviewed-by on v2 1/2
#9 lore raw
In reply to David (Ming Qiang) Wu
Quoted 9 lines · David (Ming Qiang) Wu

V2: not to add extra read-back in vcn_v4_0_5_start as there is a
read-back already. New comment for better understanding.

On VCN v4.0.5 there is a race condition where the WPTR is not updated after starting from idle when doorbell is used. The read-back of regVCN_RB1_DB_CTRL register after written is to ensure the doorbell_index is updated before it can work properly.

Quoted 6 lines
Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +4 -1
index ed00d35039c13..e55b76d71367d 100644
@@ -1034,6 +1034,10 @@ static int vcn_v4_0_5_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, regVCN_RB1_DB_CTRL);
+
        return 0;
 }
 
--

2.34.1