Skip to contentSkip to conversation

drm/atomic: attempt full modeset on page flip timeout

PATCH In review Hamza Mahfooz 5 participants 11 messages May 5 – Jul 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/2 drm/atomic: attempt full modeset on page flip timeout

We should try to recover from page flip timeouts. Forcing a full modeset should be generic across all atomic KMS drivers, so try that first.

---
 drivers/gpu/drm/drm_atomic_helper.c | 49 +++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +46 -3
index a768398a1884..7ee9d52f63c5 100644
@@ -1926,6 +1926,43 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 
+static int force_full_modeset(struct drm_crtc *crtc)
+{
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_crtc_state *crtc_state;
+	struct drm_atomic_state *state;
+	int ret;
+	int err;
+
+	if (drm_atomic_crtc_needs_modeset(crtc->state))
+		return -EBUSY;
+
+	DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, err);
+	state = drm_atomic_state_alloc(crtc->dev);
+	if (!state)
+		return -ENOMEM;
+
+	state->acquire_ctx = &ctx;
+
+	crtc_state = drm_atomic_get_crtc_state(state, crtc);
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
+		goto out;
+	}
+
+	crtc_state->mode_changed = true;
+
+	drm_info(crtc->dev,
+		 "[CRTC:%d:%s] Attempting force full modeset...\n",
+		 crtc->base.id, crtc->name);
+
+	ret = drm_atomic_commit(state);
+out:
+	drm_atomic_state_put(state);
+	DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, err);
+	return ret;
+}
+
 /**
  * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
  * @dev: DRM device
@@ -1949,17 +1986,23 @@ void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
 
 	for (i = 0; i < dev->mode_config.num_crtc; i++) {
 		struct drm_crtc_commit *commit = state->crtcs[i].commit;
-		int ret;
 
 		crtc = state->crtcs[i].ptr;
 
 		if (!crtc || !commit)
 			continue;
 
-		ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ);
-		if (ret == 0)
+		if (!wait_for_completion_timeout(&commit->flip_done, 10 * HZ)) {
+			int ret;
 			drm_err(dev, "[CRTC:%d:%s] flip_done timed out\n",
 				crtc->base.id, crtc->name);
+
+			ret = force_full_modeset(crtc);
+			if (ret)
+				drm_err(dev,
+					"[CRTC:%d:%s] force full modeset failed! ret=%d\n",
+					crtc->base.id, crtc->name, ret);
+		}
 	}
 
 	if (state->fake_commit)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v6 2/2 drm/amd/display: add DMU timeout recovery support

DMU already has robust hung state tracking, but timeout recovery was never hooked up, so do so now.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   | 13 ++++++++-----
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h   |  1 +
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c   | 12 ++++++++++--
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -5
index e96a12ff2d31..763da9a9032d 100644
@@ -1246,7 +1246,7 @@ static  void amdgpu_dm_audio_eld_notify(struct amdgpu_device *adev, int pin)
 	}
 }
 
-static int dm_dmub_hw_init(struct amdgpu_device *adev)
+int amdgpu_dm_dmub_hw_init(struct amdgpu_device *adev)
 {
 	const struct dmcub_firmware_header_v1_0 *hdr;
 	struct dmub_srv *dmub_srv = adev->dm.dmub_srv;
@@ -1315,7 +1315,7 @@ static int dm_dmub_hw_init(struct amdgpu_device *adev)
 	/* if adev->firmware.load_type == AMDGPU_FW_LOAD_PSP,
 	 * amdgpu_ucode_init_single_fw will load dmub firmware
 	 * fw_inst_const part to cw0; otherwise, the firmware back door load
-	 * will be done by dm_dmub_hw_init
+	 * will be done by amdgpu_dm_dmub_hw_init().
 	 */
 	if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
 		memcpy(fb_info->fb[DMUB_WINDOW_0_INST_CONST].cpu_addr, fw_inst_const,
@@ -1457,7 +1457,7 @@ static void dm_dmub_hw_resume(struct amdgpu_device *adev)
 			drm_warn(adev_to_drm(adev), "Wait for DMUB auto-load failed: %d\n", status);
 	} else {
 		/* Perform the full hardware initialization. */
-		r = dm_dmub_hw_init(adev);
+		r = amdgpu_dm_dmub_hw_init(adev);
 		if (r)
 			drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
 	}
@@ -2041,6 +2041,9 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
 		goto error;
 	}
 
+	adev->dm.dc->debug.enable_dmu_recovery =
+		amdgpu_device_should_recover_gpu(adev);
+
 	if (amdgpu_dc_debug_mask & DC_DISABLE_PIPE_SPLIT) {
 		adev->dm.dc->debug.force_single_disp_pipe_split = false;
 		adev->dm.dc->debug.pipe_split_policy = MPC_SPLIT_AVOID;
@@ -2090,7 +2093,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
 	if (adev->dm.dc->caps.dp_hdmi21_pcon_support)
 		drm_info(adev_to_drm(adev), "DP-HDMI FRL PCON supported\n");
 
-	r = dm_dmub_hw_init(adev);
+	r = amdgpu_dm_dmub_hw_init(adev);
 	if (r) {
 		drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
 		goto error;
@@ -3604,7 +3607,7 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
 		 */
 		link_enc_cfg_copy(adev->dm.dc->current_state, dc_state);
 
-		r = dm_dmub_hw_init(adev);
+		r = amdgpu_dm_dmub_hw_init(adev);
 		if (r) {
 			drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
 			return r;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
index 74a8fe1a1999..dc808ee83c2a 100644
@@ -1086,6 +1086,7 @@ int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256
 
 void amdgpu_dm_init_color_mod(void);
+int amdgpu_dm_dmub_hw_init(struct amdgpu_device *adev);
 int amdgpu_dm_create_color_properties(struct amdgpu_device *adev);
 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state);
 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +10 -2
index 3b8ae7798a93..8f10117483e2 100644
@@ -33,6 +33,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/amdgpu_drm.h>
+#include <drm/drm_drv.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_fixed.h>
 
@@ -1165,8 +1166,15 @@ void dm_set_dcn_clocks(struct dc_context *ctx, struct dc_clocks *clks)
 
 void dm_helpers_dmu_timeout(struct dc_context *ctx)
 {
-	// TODO:
-	//amdgpu_device_gpu_recover(dc_context->driver-context, NULL);
+	struct amdgpu_device *adev = ctx->driver_context;
+
+	lockdep_assert_held(&adev->dm.dc_lock);
+
+	drm_info(adev_to_drm(adev), "attempting firmware reset\n");
+	if (amdgpu_dm_dmub_hw_init(adev))
+		drm_dev_wedged_event(adev_to_drm(adev),
+				     DRM_WEDGE_RECOVERY_REBIND |
+				     DRM_WEDGE_RECOVERY_BUS_RESET, NULL);
 }
 
 void dm_helpers_smu_timeout(struct dc_context *ctx, unsigned int msg_id, unsigned int param, unsigned int timeout_us)
Signature · 1 line
2.54.0
Reviewed-by on v6 2/2
#2 lore raw

Re: [PATCH v6 2/2] drm/amd/display: add DMU timeout recovery support

Quoted 5 lines · Hamza Mahfooz

DMU already has robust hung state tracking, but timeout recovery was never hooked up, so do so now.

Quoted 107 lines
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   | 13 ++++++++-----
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h   |  1 +
  .../drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c   | 12 ++++++++++--
  3 files changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -5
index e96a12ff2d31..763da9a9032d 100644
@@ -1246,7 +1246,7 @@ static  void amdgpu_dm_audio_eld_notify(struct amdgpu_device *adev, int pin)
  	}
  }
 
-static int dm_dmub_hw_init(struct amdgpu_device *adev)
+int amdgpu_dm_dmub_hw_init(struct amdgpu_device *adev)
  {
  	const struct dmcub_firmware_header_v1_0 *hdr;
  	struct dmub_srv *dmub_srv = adev->dm.dmub_srv;
@@ -1315,7 +1315,7 @@ static int dm_dmub_hw_init(struct amdgpu_device *adev)
  	/* if adev->firmware.load_type == AMDGPU_FW_LOAD_PSP,
  	 * amdgpu_ucode_init_single_fw will load dmub firmware
  	 * fw_inst_const part to cw0; otherwise, the firmware back door load
-	 * will be done by dm_dmub_hw_init
+	 * will be done by amdgpu_dm_dmub_hw_init().
  	 */
  	if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
  		memcpy(fb_info->fb[DMUB_WINDOW_0_INST_CONST].cpu_addr, fw_inst_const,
@@ -1457,7 +1457,7 @@ static void dm_dmub_hw_resume(struct amdgpu_device *adev)
  			drm_warn(adev_to_drm(adev), "Wait for DMUB auto-load failed: %d\n", status);
  	} else {
  		/* Perform the full hardware initialization. */
-		r = dm_dmub_hw_init(adev);
+		r = amdgpu_dm_dmub_hw_init(adev);
  		if (r)
  			drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
  	}
@@ -2041,6 +2041,9 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
  		goto error;
  	}
 
+	adev->dm.dc->debug.enable_dmu_recovery =
+		amdgpu_device_should_recover_gpu(adev);
+
  	if (amdgpu_dc_debug_mask & DC_DISABLE_PIPE_SPLIT) {
  		adev->dm.dc->debug.force_single_disp_pipe_split = false;
  		adev->dm.dc->debug.pipe_split_policy = MPC_SPLIT_AVOID;
@@ -2090,7 +2093,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
  	if (adev->dm.dc->caps.dp_hdmi21_pcon_support)
  		drm_info(adev_to_drm(adev), "DP-HDMI FRL PCON supported\n");
 
-	r = dm_dmub_hw_init(adev);
+	r = amdgpu_dm_dmub_hw_init(adev);
  	if (r) {
  		drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
  		goto error;
@@ -3604,7 +3607,7 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
  		 */
  		link_enc_cfg_copy(adev->dm.dc->current_state, dc_state);
 
-		r = dm_dmub_hw_init(adev);
+		r = amdgpu_dm_dmub_hw_init(adev);
  		if (r) {
  			drm_err(adev_to_drm(adev), "DMUB interface failed to initialize: status=%d\n", r);
  			return r;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
index 74a8fe1a1999..dc808ee83c2a 100644
@@ -1086,6 +1086,7 @@ int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
  #define MAX_COLOR_LEGACY_LUT_ENTRIES 256
 
  void amdgpu_dm_init_color_mod(void);
+int amdgpu_dm_dmub_hw_init(struct amdgpu_device *adev);
  int amdgpu_dm_create_color_properties(struct amdgpu_device *adev);
  int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state);
  int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +10 -2
index 3b8ae7798a93..8f10117483e2 100644
@@ -33,6 +33,7 @@
  #include <drm/drm_atomic.h>
  #include <drm/drm_probe_helper.h>
  #include <drm/amdgpu_drm.h>
+#include <drm/drm_drv.h>
  #include <drm/drm_edid.h>
  #include <drm/drm_fixed.h>
 
@@ -1165,8 +1166,15 @@ void dm_set_dcn_clocks(struct dc_context *ctx, struct dc_clocks *clks)
 
  void dm_helpers_dmu_timeout(struct dc_context *ctx)
  {
-	// TODO:
-	//amdgpu_device_gpu_recover(dc_context->driver-context, NULL);
+	struct amdgpu_device *adev = ctx->driver_context;
+
+	lockdep_assert_held(&adev->dm.dc_lock);
+
+	drm_info(adev_to_drm(adev), "attempting firmware reset\n");
+	if (amdgpu_dm_dmub_hw_init(adev))
+		drm_dev_wedged_event(adev_to_drm(adev),
+				     DRM_WEDGE_RECOVERY_REBIND |
+				     DRM_WEDGE_RECOVERY_BUS_RESET, NULL);
  }
 
  void dm_helpers_smu_timeout(struct dc_context *ctx, unsigned int msg_id, unsigned int param, unsigned int timeout_us)
maintainer
#4 lore raw

Re: [PATCH v6 2/2] drm/amd/display: add DMU timeout recovery support

Quoted 8 lines · Hamza Mahfooz
Quoted 5 lines · Hamza Mahfooz

DMU already has robust hung state tracking, but timeout recovery was never hooked up, so do so now.

Does anyone mind if I merge this through drm-misc?

I'd prefer to have this go through asdn and the regular promotion testing.

One thing that some internal folks raised is that the DMUB timeout MAX_WAIT_US might be too short. On some panels, backlight control are known to take 250ms+. Triggering a DMUB reset rather than falling through may have unintended consequences.

I'll spin something up for that soon-ish.

- Leo

#5 lore raw

Re: [PATCH v6 2/2] drm/amd/display: add DMU timeout recovery support

In reply to Hamza Mahfooz

Hi,

I have been seeing what appears to be the same failure on an MSI Bravo 15 C7VF with a Ryzen 5 7535HS / Rembrandt Radeon 660M (1002:1681), an internal 1920x1080 144 Hz eDP panel, and KDE X11. It occurred on Fedora kernels 6.19 and 7.1.3. The relevant signatures included:

flip_done timed out
commit wait timed out
Error queueing DMUB command: status=2

Using amdgpu.dcdebugmask=0x810 has avoided the failure for more than 53 hours across four boots, including one continuous run longer than 27 hours.

I built this v6 series on top of v7.2-rc3 and booted it with:

amdgpu.dcdebugmask=0 amdgpu.gpu_recovery=1

It passed five DPMS off/on cycles, five modeset cycles between 60 Hz and 144 Hz, and a short fullscreen rendering test. It then ran a normal KDE X11 workload for about 12.5 hours without any DMUB queue-full, DMCUB, or page-flip timeout message.

The original intermittent timeout did not occur during that run, so I cannot offer a Tested-by for the recovery path.

After about 12.5 hours the test kernel hit a separate gfxhub VM page fault attributed to Xorg, followed by a gfx_0.0.0 ring timeout and a successful ring reset. Mesa then aborted Xorg. There were no DMUB, DMCUB, or flip timeout messages in that incident. I preserved the full AMDGPU devcoredump and symbolized userspace coredumps if they would be useful as a separate report.

Patch 1 also needed a small API adaptation on v7.2-rc3 from drm_atomic_state and drm_atomic_state_*() to drm_atomic_commit and drm_atomic_commit_*(). The resulting kernel built cleanly, and all three commits passed checkpatch.pl --strict. I can send that fixup if it would help with a respin.

Is this series still being worked on, and would testing a revised version on this Rembrandt system be useful?

Regards,
LetsDank

#6 lore raw

Re: [PATCH v6 2/2] drm/amd/display: add DMU timeout recovery support

Hi,

An important follow-up arrived shortly after my previous message.

The same separate gfxhub failure has now reproduced on the Fedora 7.1.3-200 kernel with amdgpu.dcdebugmask=0x810, after about 30.5 hours of uptime. The sequence was:

[gfxhub] page fault, process Xorg, ring 24, vmid 5 GCVM_L2_PROTECTION_FAULT_STATUS: 0x00501031 Faulty UTCL2 client ID: TCP
PERMISSION_FAULTS: 0x3
ring gfx_0.0.0 timeout
Ring gfx_0.0.0 reset succeeded

Mesa then aborted Xorg in amdgpu_ctx_set_sw_reset_status(), ending the X11 session and returning to SDDM. As in the v7.2-rc3 incident, there were no DMUB, DMCUB, flip_done, or commit-wait timeout messages.

I captured a second complete 5.4 MB AMDGPU devcoredump. The fault status, client, Xorg context, Mesa abort path, and ring-reset sequence match the v7.2-rc3 incident.

This corrects any impression that the machine is stable against all GPU faults with dcdebugmask=0x810. The workaround still appears to avoid the original DMCUB/page-flip timeout signature, but it does not prevent this separate gfxhub VM fault. The reproduction on both kernels also makes it unlikely that the gfxhub fault was introduced by this patch series.

Both devcoredumps and the matching kernel logs are available if useful.

Regards,
LetsDank

#7 lore raw

Re: [PATCH v6 2/2] drm/amd/display: add DMU timeout recovery support

In reply to LetsDank
Quoted 34 lines · LetsDank

Hi,

I have been seeing what appears to be the same failure on an MSI Bravo 15 C7VF with a Ryzen 5 7535HS / Rembrandt Radeon 660M (1002:1681), an internal 1920x1080 144 Hz eDP panel, and KDE X11. It occurred on Fedora kernels 6.19 and 7.1.3. The relevant signatures included:

flip_done timed out
commit wait timed out
Error queueing DMUB command: status=2

Using amdgpu.dcdebugmask=0x810 has avoided the failure for more than 53 hours across four boots, including one continuous run longer than 27 hours.

I built this v6 series on top of v7.2-rc3 and booted it with:

amdgpu.dcdebugmask=0 amdgpu.gpu_recovery=1

It passed five DPMS off/on cycles, five modeset cycles between 60 Hz and 144 Hz, and a short fullscreen rendering test. It then ran a normal KDE X11 workload for about 12.5 hours without any DMUB queue-full, DMCUB, or page-flip timeout message.

The original intermittent timeout did not occur during that run, so I cannot offer a Tested-by for the recovery path.

After about 12.5 hours the test kernel hit a separate gfxhub VM page fault attributed to Xorg, followed by a gfx_0.0.0 ring timeout and a successful ring reset. Mesa then aborted Xorg. There were no DMUB, DMCUB, or flip timeout messages in that incident. I preserved the full AMDGPU devcoredump and symbolized userspace coredumps if they would be useful as a separate report.

Quoted 8 lines

Patch 1 also needed a small API adaptation on v7.2-rc3 from drm_atomic_state and drm_atomic_state_*() to drm_atomic_commit and drm_atomic_commit_*(). The resulting kernel built cleanly, and all three commits passed checkpatch.pl --strict. I can send that fixup if it would help with a respin.

Is this series still being worked on, and would testing a revised version on this Rembrandt system be useful?

I haven't had much time to work on this, though if you look at the previous thread [1] the whole idea around having a recovery path for KMS was NACKed by Ville. So, it doesn't appear to me that there is much of an appetite for this.

[1] https://lore.kernel.org/r/[email protected]/

Quoted 4 lines

Regards,
LetsDank

Reviewed-by on v6 1/2
#8 lore raw
In reply to Hamza Mahfooz
Quoted 5 lines · Hamza Mahfooz

We should try to recover from page flip timeouts. Forcing a full modeset should be generic across all atomic KMS drivers, so try that first.

Quoted 79 lines
---
  drivers/gpu/drm/drm_atomic_helper.c | 49 +++++++++++++++++++++++++++--
  1 file changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +46 -3
index a768398a1884..7ee9d52f63c5 100644
@@ -1926,6 +1926,43 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
  }
  EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 
+static int force_full_modeset(struct drm_crtc *crtc)
+{
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_crtc_state *crtc_state;
+	struct drm_atomic_state *state;
+	int ret;
+	int err;
+
+	if (drm_atomic_crtc_needs_modeset(crtc->state))
+		return -EBUSY;
+
+	DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, err);
+	state = drm_atomic_state_alloc(crtc->dev);
+	if (!state)
+		return -ENOMEM;
+
+	state->acquire_ctx = &ctx;
+
+	crtc_state = drm_atomic_get_crtc_state(state, crtc);
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
+		goto out;
+	}
+
+	crtc_state->mode_changed = true;
+
+	drm_info(crtc->dev,
+		 "[CRTC:%d:%s] Attempting force full modeset...\n",
+		 crtc->base.id, crtc->name);
+
+	ret = drm_atomic_commit(state);
+out:
+	drm_atomic_state_put(state);
+	DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, err);
+	return ret;
+}
+
  /**
   * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
   * @dev: DRM device
@@ -1949,17 +1986,23 @@ void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
 
  	for (i = 0; i < dev->mode_config.num_crtc; i++) {
  		struct drm_crtc_commit *commit = state->crtcs[i].commit;
-		int ret;
 
  		crtc = state->crtcs[i].ptr;
 
  		if (!crtc || !commit)
  			continue;
 
-		ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ);
-		if (ret == 0)
+		if (!wait_for_completion_timeout(&commit->flip_done, 10 * HZ)) {
+			int ret;
  			drm_err(dev, "[CRTC:%d:%s] flip_done timed out\n",
  				crtc->base.id, crtc->name);
+
+			ret = force_full_modeset(crtc);
+			if (ret)
+				drm_err(dev,
+					"[CRTC:%d:%s] force full modeset failed! ret=%d\n",
+					crtc->base.id, crtc->name, ret);
+		}
  	}
 
  	if (state->fake_commit)
#9 lore raw
In reply to Hamza Mahfooz
Quoted 66 lines · Hamza Mahfooz

We should try to recover from page flip timeouts. Forcing a full modeset should be generic across all atomic KMS drivers, so try that first.

---
 drivers/gpu/drm/drm_atomic_helper.c | 49 +++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +37 -1
index a768398a1884..7ee9d52f63c5 100644
@@ -1926,6 +1926,43 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 
+static int force_full_modeset(struct drm_crtc *crtc)
+{
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_crtc_state *crtc_state;
+	struct drm_atomic_state *state;
+	int ret;
+	int err;
+
+	if (drm_atomic_crtc_needs_modeset(crtc->state))
+		return -EBUSY;
+
+	DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, err);
+	state = drm_atomic_state_alloc(crtc->dev);
+	if (!state)
+		return -ENOMEM;
+
+	state->acquire_ctx = &ctx;
+
+	crtc_state = drm_atomic_get_crtc_state(state, crtc);
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
+		goto out;
+	}
+
+	crtc_state->mode_changed = true;
+
+	drm_info(crtc->dev,
+		 "[CRTC:%d:%s] Attempting force full modeset...\n",
+		 crtc->base.id, crtc->name);
+
+	ret = drm_atomic_commit(state);
+out:
+	drm_atomic_state_put(state);
+	DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, err);
+	return ret;
+}
+
 /**
  * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
  * @dev: DRM device
@@ -1949,17 +1986,23 @@ void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
 
 	for (i = 0; i < dev->mode_config.num_crtc; i++) {
 		struct drm_crtc_commit *commit = state->crtcs[i].commit;
-		int ret;
 
 		crtc = state->crtcs[i].ptr;
 
 		if (!crtc || !commit)

drivers/gpu/drm/drm_atomic_helper.c void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev, · line 2000

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +4 -2
 			continue;
 
-		ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ);
-		if (ret == 0)
+		if (!wait_for_completion_timeout(&commit->flip_done, 10 * HZ)) {
+			int ret;
 			drm_err(dev, "[CRTC:%d:%s] flip_done timed out\n",
 				crtc->base.id, crtc->name);
+
+			ret = force_full_modeset(crtc);

This looks like some kind of ugly hack to paper over a driver bug. I really don't want this for i915/xe because all it'll end up doing is make it harder to debug any real issues.

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +5 -0
+			if (ret)
+				drm_err(dev,
+					"[CRTC:%d:%s] force full modeset failed! ret=%d\n",
+					crtc->base.id, crtc->name, ret);
+		}
 	}
 
 	if (state->fake_commit)
Signature · 1 line
2.54.0
Signature · 2 lines
Ville Syrjälä
Intel
#10 lore raw
Quoted 69 lines · Ville Syrjälä
Quoted 68 lines · Hamza Mahfooz

We should try to recover from page flip timeouts. Forcing a full modeset should be generic across all atomic KMS drivers, so try that first.

---
 drivers/gpu/drm/drm_atomic_helper.c | 49 +++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +37 -1
index a768398a1884..7ee9d52f63c5 100644
@@ -1926,6 +1926,43 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 
+static int force_full_modeset(struct drm_crtc *crtc)
+{
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_crtc_state *crtc_state;
+	struct drm_atomic_state *state;
+	int ret;
+	int err;
+
+	if (drm_atomic_crtc_needs_modeset(crtc->state))
+		return -EBUSY;
+
+	DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, err);
+	state = drm_atomic_state_alloc(crtc->dev);
+	if (!state)
+		return -ENOMEM;
+
+	state->acquire_ctx = &ctx;
+
+	crtc_state = drm_atomic_get_crtc_state(state, crtc);
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
+		goto out;
+	}
+
+	crtc_state->mode_changed = true;
+
+	drm_info(crtc->dev,
+		 "[CRTC:%d:%s] Attempting force full modeset...\n",
+		 crtc->base.id, crtc->name);
+
+	ret = drm_atomic_commit(state);
+out:
+	drm_atomic_state_put(state);
+	DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, err);
+	return ret;
+}
+
 /**
  * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
  * @dev: DRM device
@@ -1949,17 +1986,23 @@ void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
 
 	for (i = 0; i < dev->mode_config.num_crtc; i++) {
 		struct drm_crtc_commit *commit = state->crtcs[i].commit;
-		int ret;
 
 		crtc = state->crtcs[i].ptr;
 
 		if (!crtc || !commit)
 			continue;
 
Quoted 12 lines

drivers/gpu/drm/drm_atomic_helper.c void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev, · line 2000

Quoted 8 lines
drivers/gpu/drm/drm_atomic_helper.c +4 -2
-		ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ);
-		if (ret == 0)
+		if (!wait_for_completion_timeout(&commit->flip_done, 10 * HZ)) {
+			int ret;
 			drm_err(dev, "[CRTC:%d:%s] flip_done timed out\n",
 				crtc->base.id, crtc->name);
+
+			ret = force_full_modeset(crtc);

This looks like some kind of ugly hack to paper over a driver bug. I really don't want this for i915/xe because all it'll end up doing is make it harder to debug any real issues.

In that case, would you be okay with having drm_atomic_helper_wait_for_flip_done() return an error code, or did you have something else in mind?

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/drm_atomic_helper.c +5 -0
+			if (ret)
+				drm_err(dev,
+					"[CRTC:%d:%s] force full modeset failed! ret=%d\n",
+					crtc->base.id, crtc->name, ret);
+		}
 	}
 
 	if (state->fake_commit)
Signature · 1 line
2.54.0
Signature · 2 lines
Ville Syrjälä
Intel