Skip to contentSkip to conversation

drm/radeon: retry UVD v1 init on failure after resume

PATCH Applied ukrainer8 2 participants 3 messages Oct 22 – Oct 26

Subsystems (2)
lore
Share & tools
lore

ukrainer8

author
#0 lore raw

PATCH v3 1/1 drm/radeon: retry UVD v1 init on failure after resume

On Evergreen/Redwood (and likely other UVD v1/v2 hardware), resume from suspend intermittently fails the UVD ring test:

    radeon 0000:01:00.0: [drm] *ERROR* radeon: ring 5 test failed (0xCAFEDEAD)
    radeon 0000:01:00.0: failed initializing UVD (-22).

Cold boot always succeeds; resume succeeds only in about half of the cycles (42 measured suspend/resume cycles on a Radeon HD 5650M: OK counts per 6-cycle run were 2, 3, 5, 6, 1, 5, 3). Once the ring test fails, UVD stays dead for the rest of the session and hardware video decode silently falls back to CPU.

The resume path runs the same full asic startup as cold boot (evergreen_resume() -> evergreen_startup()), so the difference is the hardware state at entry, not a skipped call. Field data shows the first ring instance after resume is dead functionally, not by timeout: the ring test fails fast and deterministically, and only a full stop+init cycle revives the engine.

Retry the init sequence instead of giving up: on failure of clock setup, VCPU start or the ring test, fully stop UVD, let it settle for 20 ms and try again (up to 3 attempts). uvd_v1_0_stop() runs only when clock setup succeeded - MMIO writes to an unclocked UVD block can cause a PCI bus master abort and hard-hang the system. Each retry logs the failing step and the attempt number, which also makes future reports of this failure mode self-diagnosing.

On the same machine the patched driver went 6/6 OK across repeated test runs, with the retry catching exactly the failures the stock driver used to declare fatal.

v3: dropped the warm-up cycle and the widened poll window per Sashiko AI review and our own measurements (neither prevented first-attempt failures); kept the guarded retry loop.

---
v1 -> v2: guard uvd_v1_0_stop() behind successful clock setup (Sashiko AI
review: MMIO on an unclocked block can hard-hang the system). v2 -> v3: dropped the silent warm-up cycle and the 2000 ms poll window. Our measurements agree with the review: the wider window changed nothing (first attempt fails fast, not by timeout) and the warm-up did not prevent first-attempt failures (5/6 cycles) - the retry loop already does stop+settle+retry. What remains is the minimal guarded retry.

 drivers/gpu/drm/radeon/uvd_v1_0.c | 40 ++++++++++++++++++++++++++--------------
drivers/gpu/drm/radeon/uvd_v1_0.c +38 -14
@@ -158,24 +158,48 @@
 {
 	struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
 	uint32_t tmp;
-	int r;
+	int r, retry, clk_err;
 
-	/* raise clocks while booting up the VCPU */
-	if (rdev->family < CHIP_RV740)
-		radeon_set_uvd_clocks(rdev, 10000, 10000);
-	else
-		radeon_set_uvd_clocks(rdev, 53300, 40000);
+	/* after resume the first ring test can race with the hardware; retry */
+	for (retry = 0; retry < 3; retry++) {
+		/* raise clocks while booting up the VCPU */
+		if (rdev->family < CHIP_RV740)
+			clk_err = radeon_set_uvd_clocks(rdev, 10000, 10000);
+		else
+			clk_err = radeon_set_uvd_clocks(rdev, 53300, 40000);
+		r = clk_err;
+		if (r)
+			drm_warn(&rdev->ddev, "radeon: raising UVD clocks failed (%d), attempt %d\n",
+				 r, retry + 1);
 
-	r = uvd_v1_0_start(rdev);
-	if (r)
-		goto done;
+		if (!r) {
+			r = uvd_v1_0_start(rdev);
+			if (r)
+				drm_warn(&rdev->ddev, "radeon: starting UVD failed (%d), attempt %d\n",
+					 r, retry + 1);
+		}
 
-	ring->ready = true;
-	r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
-	if (r) {
-		ring->ready = false;
-		goto done;
+		if (!r) {
+			ring->ready = true;
+			r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
+			if (r) {
+				ring->ready = false;
+				drm_warn(&rdev->ddev, "radeon: UVD ring test failed (%d), attempt %d\n",
+					 r, retry + 1);
+			}
+		}
+
+		if (!r)
+			break;
+
+		/* MMIO is only safe when the block is actually clocked */
+		if (!clk_err)
+			uvd_v1_0_stop(rdev);
+		if (retry < 2)
+			mdelay(20);
 	}
+	if (r)
+		goto done;
 
 	r = radeon_ring_lock(rdev, ring, 10);
 	if (r) {
Applied
#1 lore raw
Quoted 32 lines · On Thu, Oct 22, 2026 at 6:06 AM ukrainer8 <[email protected]> wrote:

On Evergreen/Redwood (and likely other UVD v1/v2 hardware), resume from suspend intermittently fails the UVD ring test:

    radeon 0000:01:00.0: [drm] *ERROR* radeon: ring 5 test failed (0xCAFEDEAD)
    radeon 0000:01:00.0: failed initializing UVD (-22).

Cold boot always succeeds; resume succeeds only in about half of the cycles (42 measured suspend/resume cycles on a Radeon HD 5650M: OK counts per 6-cycle run were 2, 3, 5, 6, 1, 5, 3). Once the ring test fails, UVD stays dead for the rest of the session and hardware video decode silently falls back to CPU.

The resume path runs the same full asic startup as cold boot (evergreen_resume() -> evergreen_startup()), so the difference is the hardware state at entry, not a skipped call. Field data shows the first ring instance after resume is dead functionally, not by timeout: the ring test fails fast and deterministically, and only a full stop+init cycle revives the engine.

Retry the init sequence instead of giving up: on failure of clock setup, VCPU start or the ring test, fully stop UVD, let it settle for 20 ms and try again (up to 3 attempts). uvd_v1_0_stop() runs only when clock setup succeeded - MMIO writes to an unclocked UVD block can cause a PCI bus master abort and hard-hang the system. Each retry logs the failing step and the attempt number, which also makes future reports of this failure mode self-diagnosing.

On the same machine the patched driver went 6/6 OK across repeated test runs, with the retry catching exactly the failures the stock driver used to declare fatal.

Quoted 8 lines

v3: dropped the warm-up cycle and the widened poll window per Sashiko AI review and our own measurements (neither prevented first-attempt failures); kept the guarded retry loop.

Picked up this one in place of v2. Thanks!

Alex

Quoted 74 lines

---
v1 -> v2: guard uvd_v1_0_stop() behind successful clock setup (Sashiko AI
review: MMIO on an unclocked block can hard-hang the system). v2 -> v3: dropped the silent warm-up cycle and the 2000 ms poll window. Our measurements agree with the review: the wider window changed nothing (first attempt fails fast, not by timeout) and the warm-up did not prevent first-attempt failures (5/6 cycles) - the retry loop already does stop+settle+retry. What remains is the minimal guarded retry.

 drivers/gpu/drm/radeon/uvd_v1_0.c | 40 ++++++++++++++++++++++++++--------------
drivers/gpu/drm/radeon/uvd_v1_0.c +38 -14
@@ -158,24 +158,48 @@
 {
        struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
        uint32_t tmp;
-       int r;
+       int r, retry, clk_err;
 
-       /* raise clocks while booting up the VCPU */
-       if (rdev->family < CHIP_RV740)
-               radeon_set_uvd_clocks(rdev, 10000, 10000);
-       else
-               radeon_set_uvd_clocks(rdev, 53300, 40000);
+       /* after resume the first ring test can race with the hardware; retry */
+       for (retry = 0; retry < 3; retry++) {
+               /* raise clocks while booting up the VCPU */
+               if (rdev->family < CHIP_RV740)
+                       clk_err = radeon_set_uvd_clocks(rdev, 10000, 10000);
+               else
+                       clk_err = radeon_set_uvd_clocks(rdev, 53300, 40000);
+               r = clk_err;
+               if (r)
+                       drm_warn(&rdev->ddev, "radeon: raising UVD clocks failed (%d), attempt %d\n",
+                                r, retry + 1);
 
-       r = uvd_v1_0_start(rdev);
-       if (r)
-               goto done;
+               if (!r) {
+                       r = uvd_v1_0_start(rdev);
+                       if (r)
+                               drm_warn(&rdev->ddev, "radeon: starting UVD failed (%d), attempt %d\n",
+                                        r, retry + 1);
+               }
 
-       ring->ready = true;
-       r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
-       if (r) {
-               ring->ready = false;
-               goto done;
+               if (!r) {
+                       ring->ready = true;
+                       r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
+                       if (r) {
+                               ring->ready = false;
+                               drm_warn(&rdev->ddev, "radeon: UVD ring test failed (%d), attempt %d\n",
+                                        r, retry + 1);
+                       }
+               }
+
+               if (!r)
+                       break;
+
+               /* MMIO is only safe when the block is actually clocked */
+               if (!clk_err)
+                       uvd_v1_0_stop(rdev);
+               if (retry < 2)
+                       mdelay(20);
        }
+       if (r)
+               goto done;
 
        r = radeon_ring_lock(rdev, ring, 10);
        if (r) {
author
#2 lore raw

Thanks! Happy to help if any fallout reports come in.

Regards
Oleg

чт, 22 жовт. 2026 р. о 18:44 Alex Deucher <[email protected]> пише:

Quoted 121 lines · On Thu, Oct 22, 2026 at 6:06 AM ukrainer8 <[email protected]> wrote:
Quoted 32 lines

On Evergreen/Redwood (and likely other UVD v1/v2 hardware), resume from suspend intermittently fails the UVD ring test:

    radeon 0000:01:00.0: [drm] *ERROR* radeon: ring 5 test failed (0xCAFEDEAD)
    radeon 0000:01:00.0: failed initializing UVD (-22).

Cold boot always succeeds; resume succeeds only in about half of the cycles (42 measured suspend/resume cycles on a Radeon HD 5650M: OK counts per 6-cycle run were 2, 3, 5, 6, 1, 5, 3). Once the ring test fails, UVD stays dead for the rest of the session and hardware video decode silently falls back to CPU.

The resume path runs the same full asic startup as cold boot (evergreen_resume() -> evergreen_startup()), so the difference is the hardware state at entry, not a skipped call. Field data shows the first ring instance after resume is dead functionally, not by timeout: the ring test fails fast and deterministically, and only a full stop+init cycle revives the engine.

Retry the init sequence instead of giving up: on failure of clock setup, VCPU start or the ring test, fully stop UVD, let it settle for 20 ms and try again (up to 3 attempts). uvd_v1_0_stop() runs only when clock setup succeeded - MMIO writes to an unclocked UVD block can cause a PCI bus master abort and hard-hang the system. Each retry logs the failing step and the attempt number, which also makes future reports of this failure mode self-diagnosing.

On the same machine the patched driver went 6/6 OK across repeated test runs, with the retry catching exactly the failures the stock driver used to declare fatal.

Quoted 8 lines

v3: dropped the warm-up cycle and the widened poll window per Sashiko AI review and our own measurements (neither prevented first-attempt failures); kept the guarded retry loop.

Picked up this one in place of v2. Thanks!

Alex

Quoted 74 lines

---
v1 -> v2: guard uvd_v1_0_stop() behind successful clock setup (Sashiko AI
review: MMIO on an unclocked block can hard-hang the system). v2 -> v3: dropped the silent warm-up cycle and the 2000 ms poll window. Our measurements agree with the review: the wider window changed nothing (first attempt fails fast, not by timeout) and the warm-up did not prevent first-attempt failures (5/6 cycles) - the retry loop already does stop+settle+retry. What remains is the minimal guarded retry.

 drivers/gpu/drm/radeon/uvd_v1_0.c | 40 ++++++++++++++++++++++++++--------------
drivers/gpu/drm/radeon/uvd_v1_0.c +38 -14
@@ -158,24 +158,48 @@
 {
        struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
        uint32_t tmp;
-       int r;
+       int r, retry, clk_err;
 
-       /* raise clocks while booting up the VCPU */
-       if (rdev->family < CHIP_RV740)
-               radeon_set_uvd_clocks(rdev, 10000, 10000);
-       else
-               radeon_set_uvd_clocks(rdev, 53300, 40000);
+       /* after resume the first ring test can race with the hardware; retry */
+       for (retry = 0; retry < 3; retry++) {
+               /* raise clocks while booting up the VCPU */
+               if (rdev->family < CHIP_RV740)
+                       clk_err = radeon_set_uvd_clocks(rdev, 10000, 10000);
+               else
+                       clk_err = radeon_set_uvd_clocks(rdev, 53300, 40000);
+               r = clk_err;
+               if (r)
+                       drm_warn(&rdev->ddev, "radeon: raising UVD clocks failed (%d), attempt %d\n",
+                                r, retry + 1);
 
-       r = uvd_v1_0_start(rdev);
-       if (r)
-               goto done;
+               if (!r) {
+                       r = uvd_v1_0_start(rdev);
+                       if (r)
+                               drm_warn(&rdev->ddev, "radeon: starting UVD failed (%d), attempt %d\n",
+                                        r, retry + 1);
+               }
 
-       ring->ready = true;
-       r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
-       if (r) {
-               ring->ready = false;
-               goto done;
+               if (!r) {
+                       ring->ready = true;
+                       r = radeon_ring_test(rdev, R600_RING_TYPE_UVD_INDEX, ring);
+                       if (r) {
+                               ring->ready = false;
+                               drm_warn(&rdev->ddev, "radeon: UVD ring test failed (%d), attempt %d\n",
+                                        r, retry + 1);
+                       }
+               }
+
+               if (!r)
+                       break;
+
+               /* MMIO is only safe when the block is actually clocked */
+               if (!clk_err)
+                       uvd_v1_0_stop(rdev);
+               if (retry < 2)
+                       mdelay(20);
        }
+       if (r)
+               goto done;
 
        r = radeon_ring_lock(rdev, ring, 10);
        if (r) {