Skip to contentSkip to conversation

drm/i915: Fix modeset handling during gpu reset, v2.

PATCH In review Maarten Lankhorst 4 participants 10 messages May 2, 2016 – May 11, 2016

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

PATCH 1/2 drm/i915: Fix modeset handling during gpu reset, v2.

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 141 ++++++++++++++++++++++-------------
 1 file changed, 89 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/intel_display.c +89 -52
index 2f36414702fe..4fb904f2bcf9 100644
@@ -3144,27 +3144,83 @@ static void intel_update_primary_planes(struct drm_device *dev)
 	}
 }
 
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
+
+	if (!state)
+		return 0;
+
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		/*
+		 * Force recalculation even if we restore
+		 * current state. With fast modeset this may not result
+		 * in a modeset when the state is compatible.
+		 */
+		crtc_state->mode_changed = true;
+	}
+
+	return drm_atomic_commit(state);
+}
+
 void intel_prepare_reset(struct drm_device *dev)
 {
+	struct drm_atomic_state *state;
+	struct drm_modeset_acquire_ctx *pctx;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	int ret;
+
 	/* no reset support for gen2 */
-	if (IS_GEN2(dev))
+	if (IS_GEN2(dev_priv))
 		return;
 
-	/* reset doesn't touch the display */
-	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+	drm_modeset_lock_all(dev);
+
+	/* reset doesn't touch the display, but flips might get nuked anyway, */
+	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
 		return;
 
-	drm_modeset_lock_all(dev);
+	pctx = dev->mode_config.acquire_ctx;
+
 	/*
 	 * Disabling the crtcs gracefully seems nicer. Also the
 	 * g33 docs say we should at least disable all the planes.
 	 */
-	intel_display_suspend(dev);
+
+	state = drm_atomic_helper_duplicate_state(dev, pctx);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
+		state = NULL;
+		DRM_ERROR("Duplicating state failed with %i\n", ret);
+		goto err;
+	}
+
+	ret = drm_atomic_helper_disable_all(dev, pctx);
+	if (ret) {
+		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
+		goto err;
+	}
+
+	dev_priv->modeset_restore_state = state;
+	state->acquire_ctx = pctx;
+	return;
+
+err:
+	drm_atomic_state_free(state);
 }
 
 void intel_finish_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = to_i915(dev);
+	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
+	int ret;
 
 	/*
 	 * Flips in the rings will be nuked by the reset,
@@ -3177,6 +3233,8 @@ void intel_finish_reset(struct drm_device *dev)
 	if (IS_GEN2(dev))
 		return;
 
+	dev_priv->modeset_restore_state = NULL;
+
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
 		/*
@@ -3189,26 +3247,27 @@ void intel_finish_reset(struct drm_device *dev)
 		 * CS-based flips (which might get lost in gpu resets) any more.
 		 */
 		intel_update_primary_planes(dev);
-		return;
-	}
-
-	/*
-	 * The display has been reset as well,
-	 * so need a full re-initialization.
-	 */
-	intel_runtime_pm_disable_interrupts(dev_priv);
-	intel_runtime_pm_enable_interrupts(dev_priv);
+	} else {
+		/*
+		 * The display has been reset as well,
+		 * so need a full re-initialization.
+		 */
+		intel_runtime_pm_disable_interrupts(dev_priv);
+		intel_runtime_pm_enable_interrupts(dev_priv);
 
-	intel_modeset_init_hw(dev);
+		intel_modeset_init_hw(dev);
 
-	spin_lock_irq(&dev_priv->irq_lock);
-	if (dev_priv->display.hpd_irq_setup)
-		dev_priv->display.hpd_irq_setup(dev);
-	spin_unlock_irq(&dev_priv->irq_lock);
+		spin_lock_irq(&dev_priv->irq_lock);
+		if (dev_priv->display.hpd_irq_setup)
+			dev_priv->display.hpd_irq_setup(dev);
+		spin_unlock_irq(&dev_priv->irq_lock);
 
-	intel_display_resume(dev);
+		ret = __intel_display_resume(dev, state);
+		if (ret)
+			DRM_ERROR("Restoring old state failed with %i\n", ret);
 
-	intel_hpd_init(dev_priv);
+		intel_hpd_init(dev_priv);
+	}
 
 	drm_modeset_unlock_all(dev);
 }
@@ -15957,9 +16016,10 @@ void intel_display_resume(struct drm_device *dev)
 	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
-	bool setup = false;
 
 	dev_priv->modeset_restore_state = NULL;
+	if (state)
+		state->acquire_ctx = &ctx;
 
 	/*
 	 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -15970,40 +16030,17 @@ void intel_display_resume(struct drm_device *dev)
 	mutex_lock(&dev->mode_config.mutex);
 	drm_modeset_acquire_init(&ctx, 0);
 
-retry:
-	ret = drm_modeset_lock_all_ctx(dev, &ctx);
-
-	if (ret == 0 && !setup) {
-		setup = true;
-
-		intel_modeset_setup_hw_state(dev);
-		i915_redisable_vga(dev);
-	}
-
-	if (ret == 0 && state) {
-		struct drm_crtc_state *crtc_state;
-		struct drm_crtc *crtc;
-		int i;
-
-		state->acquire_ctx = &ctx;
-
-		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			/*
-			 * Force recalculation even if we restore
-			 * current state. With fast modeset this may not result
-			 * in a modeset when the state is compatible.
-			 */
-			crtc_state->mode_changed = true;
-		}
-
-		ret = drm_atomic_commit(state);
-	}
+	while (1) {
+		ret = drm_modeset_lock_all_ctx(dev, &ctx);
+		if (ret != -EDEADLK)
+			break;
 
-	if (ret == -EDEADLK) {
 		drm_modeset_backoff(&ctx);
-		goto retry;
 	}
 
+	ret = __intel_display_resume(dev, state);
+	WARN_ON(ret == -EDEADLK);
+
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 	mutex_unlock(&dev->mode_config.mutex);
Signature · 6 lines
2.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/2 drm/i915: Add a way to test the modeset done during gpu reset, v3.

Add force_reset_modeset_test as a parameter to force the modeset path during gpu reset. This allows a IGT test to set the knob and trigger a hang to force the gpu reset, even on platforms that wouldn't otherwise require it.

Changes since v1:
- Split out fix to separate commit.
Changes since v2:
- This commit is purely about force_reset_modeset_test now.

Testcase: drv_hangman.reset-with-forced-modeset

---
 drivers/gpu/drm/i915/i915_params.c   |  6 ++++++
 drivers/gpu/drm/i915/i915_params.h   |  1 +
 drivers/gpu/drm/i915/intel_display.c | 30 +++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_params.c +6 -0
index 383c076919ed..ec3a03bfe3b0 100644
@@ -45,6 +45,7 @@ struct i915_params i915 __read_mostly = {
 	.fastboot = 0,
 	.prefault_disable = 0,
 	.load_detect_test = 0,
+	.force_reset_modeset_test = 0,
 	.reset = true,
 	.invert_brightness = 0,
 	.disable_display = 0,
@@ -159,6 +160,11 @@ MODULE_PARM_DESC(load_detect_test,
 	"Force-enable the VGA load detect code for testing (default:false). "
 	"For developers only.");
 
+module_param_named_unsafe(force_reset_modeset_test, i915.force_reset_modeset_test, bool, 0600);
+MODULE_PARM_DESC(force_reset_modeset_test,
+	"Force a modeset during gpu reset for testing (default:false). "
+	"For developers only.");
+
 module_param_named_unsafe(invert_brightness, i915.invert_brightness, int, 0600);
 MODULE_PARM_DESC(invert_brightness,
 	"Invert backlight brightness "
drivers/gpu/drm/i915/i915_params.h +1 -0
index 65e73dd7d970..76c556a30461 100644
@@ -55,6 +55,7 @@ struct i915_params {
 	bool fastboot;
 	bool prefault_disable;
 	bool load_detect_test;
+	bool force_reset_modeset_test;
 	bool reset;
 	bool disable_display;
 	bool enable_guc_submission;
drivers/gpu/drm/i915/intel_display.c +19 -11
index 4fb904f2bcf9..153039cc3ae8 100644
@@ -3184,7 +3184,8 @@ void intel_prepare_reset(struct drm_device *dev)
 	drm_modeset_lock_all(dev);
 
 	/* reset doesn't touch the display, but flips might get nuked anyway, */
-	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
+	if (!i915.force_reset_modeset_test &&
+	    (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv)))
 		return;
 
 	pctx = dev->mode_config.acquire_ctx;
@@ -3237,16 +3238,23 @@ void intel_finish_reset(struct drm_device *dev)
 
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
-		/*
-		 * Flips in the rings have been nuked by the reset,
-		 * so update the base address of all primary
-		 * planes to the the last fb to make sure we're
-		 * showing the correct fb after a reset.
-		 *
-		 * FIXME: Atomic will make this obsolete since we won't schedule
-		 * CS-based flips (which might get lost in gpu resets) any more.
-		 */
-		intel_update_primary_planes(dev);
+		if (!state) {
+			/*
+			 * Flips in the rings have been nuked by the reset,
+			 * so update the base address of all primary
+			 * planes to the the last fb to make sure we're
+			 * showing the correct fb after a reset.
+			 *
+			 * FIXME: Atomic will make this obsolete since we won't schedule
+			 * CS-based flips (which might get lost in gpu resets) any more.
+			 */
+			intel_update_primary_planes(dev);
+		} else {
+			ret = __intel_display_resume(dev, state);
+
+			if (ret)
+				DRM_ERROR("Restoring old state failed with %i\n", ret);
+		}
 	} else {
 		/*
 		 * The display has been reset as well,
Signature · 6 lines
2.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

✗ Fi.CI.BAT: failure for series starting with [1/2] drm/i915: Fix modeset handling during gpu reset, v2.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: series starting with [1/2] drm/i915: Fix modeset handling during gpu reset, v2.
URL : https://patchwork.freedesktop.org/series/6600/
State : failure

== Summary ==

Series 6600v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/6600/revisions/1/mbox/

Test drv_hangman:

        Subgroup error-state-basic:
                pass       -> INCOMPLETE (snb-x220t)
                pass       -> INCOMPLETE (bdw-nuci7-2)
                pass       -> INCOMPLETE (ilk-hp8440p)
Test gem_ringfill:
        Subgroup basic-default-hang:
                pass       -> INCOMPLETE (snb-dellxps)
                pass       -> INCOMPLETE (skl-nuci5)
Test kms_pipe_crc_basic:
        Subgroup hang-read-crc-pipe-a:
                pass       -> INCOMPLETE (bdw-ultra)
                pass       -> INCOMPLETE (skl-i7k-2)
                pass       -> INCOMPLETE (byt-nuc)
        Subgroup hang-read-crc-pipe-b:
                skip       -> INCOMPLETE (bsw-nuc-2)
                pass       -> INCOMPLETE (hsw-gt2)
                pass       -> INCOMPLETE (ivb-t430s)
bdw-nuci7-2      total:5    pass:4    dwarn:0   dfail:0   fail:0   skip:0  
bdw-ultra        total:95   pass:83   dwarn:0   dfail:0   fail:0   skip:11 
bsw-nuc-2        total:87   pass:67   dwarn:0   dfail:0   fail:0   skip:19 
byt-nuc          total:53   pass:42   dwarn:0   dfail:0   fail:1   skip:9  
hsw-brixbox      total:21   pass:16   dwarn:0   dfail:0   fail:0   skip:4  
hsw-gt2          total:12   pass:11   dwarn:0   dfail:0   fail:0   skip:0  
ilk-hp8440p      total:43   pass:33   dwarn:0   dfail:0   fail:0   skip:9  
ivb-t430s        total:35   pass:31   dwarn:0   dfail:0   fail:0   skip:3  
skl-i7k-2        total:35   pass:30   dwarn:0   dfail:0   fail:0   skip:4  
skl-nuci5        total:48   pass:45   dwarn:0   dfail:0   fail:0   skip:2  
snb-dellxps      total:6    pass:4    dwarn:0   dfail:0   fail:0   skip:1  
snb-x220t        total:69   pass:55   dwarn:0   dfail:0   fail:0   skip:13 

Results at /archive/results/CI_IGT_test/Patchwork_2123/

5256d5ce241debab2267faf6dc2d5ad9eaca9554 drm-intel-nightly: 2016y-05m-02d-07h-51m-16s UTC integration manifest 7410f53 drm/i915: Add a way to test the modeset done during gpu reset, v3.
089f414 drm/i915: Fix modeset handling during gpu reset, v2.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Maarten Lankhorst
Quoted 9 lines · Maarten Lankhorst

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked.

Found this patch by accident. --in-reply-to would have helped a bit.

Quoted 30 lines
Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 141 ++++++++++++++++++++++-------------
 1 file changed, 89 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/intel_display.c +14 -0
index 2f36414702fe..4fb904f2bcf9 100644
@@ -3144,27 +3144,83 @@ static void intel_update_primary_planes(struct drm_device *dev)
 	}
 }
 
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
+
+	if (!state)
+		return 0;
+

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3170

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10 -0
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		/*
+		 * Force recalculation even if we restore
+		 * current state. With fast modeset this may not result
+		 * in a modeset when the state is compatible.
+		 */
+		crtc_state->mode_changed = true;
+	}
+
+	return drm_atomic_commit(state);

The -EDEADLK warn could be here so we don't have to duplicate it in two places perhaps? Extracting __intel_display_reset() could also be a separate patch to make this stuff a bit easier to review.

Oh and BTW resume is also broken on platforms that have the force pipe A quirk. I do have some patches lined up to nuke that quirk for good, which I should probably post sooner rather than later. But those have at least a theoretical chance of regressing something, so in the meantime I think we'll still need to fix this thing for the normal resume path as well.

Quoted 7 lines
drivers/gpu/drm/i915/intel_display.c +5 -0
+}
+
 void intel_prepare_reset(struct drm_device *dev)
 {
+	struct drm_atomic_state *state;
+	struct drm_modeset_acquire_ctx *pctx;
+	struct drm_i915_private *dev_priv = to_i915(dev);

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3184

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +4 -3
+	int ret;
+
 	/* no reset support for gen2 */
-	if (IS_GEN2(dev))
+	if (IS_GEN2(dev_priv))
 		return;
 
-	/* reset doesn't touch the display */
-	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+	drm_modeset_lock_all(dev);

Isn't that going to clash with the locking in
intel_update_primary_planes() ?

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3190

Quoted 7 lines
drivers/gpu/drm/i915/intel_display.c +4 -1
+
+	/* reset doesn't touch the display, but flips might get nuked anyway, */
+	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
 		return;
 
-	drm_modeset_lock_all(dev);
+	pctx = dev->mode_config.acquire_ctx;

Still looks like power context.

Quoted 135 lines
drivers/gpu/drm/i915/intel_display.c +46 -46
+
 	/*
 	 * Disabling the crtcs gracefully seems nicer. Also the
 	 * g33 docs say we should at least disable all the planes.
 	 */
-	intel_display_suspend(dev);
+
+	state = drm_atomic_helper_duplicate_state(dev, pctx);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
+		state = NULL;
+		DRM_ERROR("Duplicating state failed with %i\n", ret);
+		goto err;
+	}
+
+	ret = drm_atomic_helper_disable_all(dev, pctx);
+	if (ret) {
+		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
+		goto err;
+	}
+
+	dev_priv->modeset_restore_state = state;
+	state->acquire_ctx = pctx;
+	return;
+
+err:
+	drm_atomic_state_free(state);
 }
 
 void intel_finish_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = to_i915(dev);
+	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
+	int ret;
 
 	/*
 	 * Flips in the rings will be nuked by the reset,
@@ -3177,6 +3233,8 @@ void intel_finish_reset(struct drm_device *dev)
 	if (IS_GEN2(dev))
 		return;
 
+	dev_priv->modeset_restore_state = NULL;
+
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
 		/*
@@ -3189,26 +3247,27 @@ void intel_finish_reset(struct drm_device *dev)
 		 * CS-based flips (which might get lost in gpu resets) any more.
 		 */
 		intel_update_primary_planes(dev);
-		return;
-	}
-
-	/*
-	 * The display has been reset as well,
-	 * so need a full re-initialization.
-	 */
-	intel_runtime_pm_disable_interrupts(dev_priv);
-	intel_runtime_pm_enable_interrupts(dev_priv);
+	} else {
+		/*
+		 * The display has been reset as well,
+		 * so need a full re-initialization.
+		 */
+		intel_runtime_pm_disable_interrupts(dev_priv);
+		intel_runtime_pm_enable_interrupts(dev_priv);
 
-	intel_modeset_init_hw(dev);
+		intel_modeset_init_hw(dev);
 
-	spin_lock_irq(&dev_priv->irq_lock);
-	if (dev_priv->display.hpd_irq_setup)
-		dev_priv->display.hpd_irq_setup(dev);
-	spin_unlock_irq(&dev_priv->irq_lock);
+		spin_lock_irq(&dev_priv->irq_lock);
+		if (dev_priv->display.hpd_irq_setup)
+			dev_priv->display.hpd_irq_setup(dev);
+		spin_unlock_irq(&dev_priv->irq_lock);
 
-	intel_display_resume(dev);
+		ret = __intel_display_resume(dev, state);
+		if (ret)
+			DRM_ERROR("Restoring old state failed with %i\n", ret);
 
-	intel_hpd_init(dev_priv);
+		intel_hpd_init(dev_priv);
+	}
 
 	drm_modeset_unlock_all(dev);
 }
@@ -15957,9 +16016,10 @@ void intel_display_resume(struct drm_device *dev)
 	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
-	bool setup = false;
 
 	dev_priv->modeset_restore_state = NULL;
+	if (state)
+		state->acquire_ctx = &ctx;
 
 	/*
 	 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -15970,40 +16030,17 @@ void intel_display_resume(struct drm_device *dev)
 	mutex_lock(&dev->mode_config.mutex);
 	drm_modeset_acquire_init(&ctx, 0);
 
-retry:
-	ret = drm_modeset_lock_all_ctx(dev, &ctx);
-
-	if (ret == 0 && !setup) {
-		setup = true;
-
-		intel_modeset_setup_hw_state(dev);
-		i915_redisable_vga(dev);
-	}
-
-	if (ret == 0 && state) {
-		struct drm_crtc_state *crtc_state;
-		struct drm_crtc *crtc;
-		int i;
-
-		state->acquire_ctx = &ctx;
-
-		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			/*
-			 * Force recalculation even if we restore
-			 * current state. With fast modeset this may not result
-			 * in a modeset when the state is compatible.
-			 */
-			crtc_state->mode_changed = true;
-		}
-
-		ret = drm_atomic_commit(state);
-	}
+	while (1) {

drivers/gpu/drm/i915/intel_display.c void intel_display_resume(struct drm_device *dev) · line 16041

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +4 -2
+		ret = drm_modeset_lock_all_ctx(dev, &ctx);
+		if (ret != -EDEADLK)
+			break;
 
-	if (ret == -EDEADLK) {
 		drm_modeset_backoff(&ctx);
-		goto retry;
 	}
 
+	ret = __intel_display_resume(dev, state);

Shouldn't we skip this call if the lock_all failed?

Quoted 12 lines
drivers/gpu/drm/i915/intel_display.c +2 -0
+	WARN_ON(ret == -EDEADLK);
+
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 	mutex_unlock(&dev->mode_config.mutex);
Signature · 6 lines
2.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Op 06-05-16 om 15:06 schreef Ville Syrjälä:

Quoted 75 lines · Maarten Lankhorst
Quoted 9 lines

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked.

Found this patch by accident. --in-reply-to would have helped a bit.

Quoted 29 lines
Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 141 ++++++++++++++++++++++-------------
 1 file changed, 89 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/intel_display.c +14 -0
index 2f36414702fe..4fb904f2bcf9 100644
@@ -3144,27 +3144,83 @@ static void intel_update_primary_planes(struct drm_device *dev)
 	}
 }
 
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
+
+	if (!state)
+		return 0;
+

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3170

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10 -0
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		/*
+		 * Force recalculation even if we restore
+		 * current state. With fast modeset this may not result
+		 * in a modeset when the state is compatible.
+		 */
+		crtc_state->mode_changed = true;
+	}
+
+	return drm_atomic_commit(state);

The -EDEADLK warn could be here so we don't have to duplicate it in two places perhaps? Extracting __intel_display_reset() could also be a separate patch to make this stuff a bit easier to review.

Oh and BTW resume is also broken on platforms that have the force pipe A quirk. I do have some patches lined up to nuke that quirk for good, which I should probably post sooner rather than later. But those have at least a theoretical chance of regressing something, so in the meantime I think we'll still need to fix this thing for the normal resume path as well.

Quoted 14 lines
drivers/gpu/drm/i915/intel_display.c +8 -1
+}
+
 void intel_prepare_reset(struct drm_device *dev)
 {
+	struct drm_atomic_state *state;
+	struct drm_modeset_acquire_ctx *pctx;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	int ret;
+
 	/* no reset support for gen2 */
-	if (IS_GEN2(dev))
+	if (IS_GEN2(dev_priv))
 		return;
 
Quoted 5 lines

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3184

Quoted 3 lines
drivers/gpu/drm/i915/intel_display.c +1 -2
-	/* reset doesn't touch the display */
-	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+	drm_modeset_lock_all(dev);

Isn't that going to clash with the locking in
intel_update_primary_planes() ?

Oops indeed, thanks for catching.

Quoted 8 lines

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3190

Quoted 7 lines
drivers/gpu/drm/i915/intel_display.c +4 -1
+
+	/* reset doesn't touch the display, but flips might get nuked anyway, */
+	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
 		return;
 
-	drm_modeset_lock_all(dev);
+	pctx = dev->mode_config.acquire_ctx;

Still looks like power context.

Will change to ctx.

Quoted 139 lines
Quoted 139 lines
drivers/gpu/drm/i915/intel_display.c +49 -46
+
 	/*
 	 * Disabling the crtcs gracefully seems nicer. Also the
 	 * g33 docs say we should at least disable all the planes.
 	 */
-	intel_display_suspend(dev);
+
+	state = drm_atomic_helper_duplicate_state(dev, pctx);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
+		state = NULL;
+		DRM_ERROR("Duplicating state failed with %i\n", ret);
+		goto err;
+	}
+
+	ret = drm_atomic_helper_disable_all(dev, pctx);
+	if (ret) {
+		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
+		goto err;
+	}
+
+	dev_priv->modeset_restore_state = state;
+	state->acquire_ctx = pctx;
+	return;
+
+err:
+	drm_atomic_state_free(state);
 }
 
 void intel_finish_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = to_i915(dev);
+	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
+	int ret;
 
 	/*
 	 * Flips in the rings will be nuked by the reset,
@@ -3177,6 +3233,8 @@ void intel_finish_reset(struct drm_device *dev)
 	if (IS_GEN2(dev))
 		return;
 
+	dev_priv->modeset_restore_state = NULL;
+
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
 		/*
@@ -3189,26 +3247,27 @@ void intel_finish_reset(struct drm_device *dev)
 		 * CS-based flips (which might get lost in gpu resets) any more.
 		 */
 		intel_update_primary_planes(dev);
-		return;
-	}
-
-	/*
-	 * The display has been reset as well,
-	 * so need a full re-initialization.
-	 */
-	intel_runtime_pm_disable_interrupts(dev_priv);
-	intel_runtime_pm_enable_interrupts(dev_priv);
+	} else {
+		/*
+		 * The display has been reset as well,
+		 * so need a full re-initialization.
+		 */
+		intel_runtime_pm_disable_interrupts(dev_priv);
+		intel_runtime_pm_enable_interrupts(dev_priv);
 
-	intel_modeset_init_hw(dev);
+		intel_modeset_init_hw(dev);
 
-	spin_lock_irq(&dev_priv->irq_lock);
-	if (dev_priv->display.hpd_irq_setup)
-		dev_priv->display.hpd_irq_setup(dev);
-	spin_unlock_irq(&dev_priv->irq_lock);
+		spin_lock_irq(&dev_priv->irq_lock);
+		if (dev_priv->display.hpd_irq_setup)
+			dev_priv->display.hpd_irq_setup(dev);
+		spin_unlock_irq(&dev_priv->irq_lock);
 
-	intel_display_resume(dev);
+		ret = __intel_display_resume(dev, state);
+		if (ret)
+			DRM_ERROR("Restoring old state failed with %i\n", ret);
 
-	intel_hpd_init(dev_priv);
+		intel_hpd_init(dev_priv);
+	}
 
 	drm_modeset_unlock_all(dev);
 }
@@ -15957,9 +16016,10 @@ void intel_display_resume(struct drm_device *dev)
 	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
-	bool setup = false;
 
 	dev_priv->modeset_restore_state = NULL;
+	if (state)
+		state->acquire_ctx = &ctx;
 
 	/*
 	 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -15970,40 +16030,17 @@ void intel_display_resume(struct drm_device *dev)
 	mutex_lock(&dev->mode_config.mutex);
 	drm_modeset_acquire_init(&ctx, 0);
 
-retry:
-	ret = drm_modeset_lock_all_ctx(dev, &ctx);
-
-	if (ret == 0 && !setup) {
-		setup = true;
-
-		intel_modeset_setup_hw_state(dev);
-		i915_redisable_vga(dev);
-	}
-
-	if (ret == 0 && state) {
-		struct drm_crtc_state *crtc_state;
-		struct drm_crtc *crtc;
-		int i;
-
-		state->acquire_ctx = &ctx;
-
-		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			/*
-			 * Force recalculation even if we restore
-			 * current state. With fast modeset this may not result
-			 * in a modeset when the state is compatible.
-			 */
-			crtc_state->mode_changed = true;
-		}
-
-		ret = drm_atomic_commit(state);
-	}
+	while (1) {
+		ret = drm_modeset_lock_all_ctx(dev, &ctx);
+		if (ret != -EDEADLK)
+			break;
 
Quoted 7 lines

drivers/gpu/drm/i915/intel_display.c void intel_display_resume(struct drm_device *dev) · line 16041

Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +1 -2
-	if (ret == -EDEADLK) {
 		drm_modeset_backoff(&ctx);
-		goto retry;
 	}
 
+	ret = __intel_display_resume(dev, state);

Shouldn't we skip this call if the lock_all failed?

I guess for paranoia I could, but the locking can only fail with EDEADLK or EALREADY. EALREADY is mapped to 0 since multiple locking calls are allowed, so can realistically only fail with -EDEADLK, won't even be able to fail with -EINTR in the future since s/r is not interruptible.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

PATCH v3 1/2 drm/i915: Fix modeset handling during gpu reset, v3.

In reply to Ville Syrjälä

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 150 ++++++++++++++++++++++-------------
 1 file changed, 93 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/intel_display.c +93 -57
index 14e05091c397..6faa529f35df 100644
@@ -3130,41 +3130,96 @@ static void intel_update_primary_planes(struct drm_device *dev)
 
 	for_each_crtc(dev, crtc) {
 		struct intel_plane *plane = to_intel_plane(crtc->primary);
-		struct intel_plane_state *plane_state;
-
-		drm_modeset_lock_crtc(crtc, &plane->base);
-		plane_state = to_intel_plane_state(plane->base.state);
+		struct intel_plane_state *plane_state =
+			to_intel_plane_state(plane->base.state);
 
 		if (plane_state->visible)
 			plane->update_plane(&plane->base,
 					    to_intel_crtc_state(crtc->state),
 					    plane_state);
+	}
+}
+
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i, ret;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
 
-		drm_modeset_unlock_crtc(crtc);
+	if (!state)
+		return 0;
+
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		/*
+		 * Force recalculation even if we restore
+		 * current state. With fast modeset this may not result
+		 * in a modeset when the state is compatible.
+		 */
+		crtc_state->mode_changed = true;
 	}
+
+	ret = drm_atomic_commit(state);
+
+	WARN_ON(ret == -EDEADLK);
+	return ret;
 }
 
 void intel_prepare_reset(struct drm_device *dev)
 {
+	struct drm_atomic_state *state;
+	struct drm_modeset_acquire_ctx *ctx;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	int ret;
+
 	/* no reset support for gen2 */
-	if (IS_GEN2(dev))
+	if (IS_GEN2(dev_priv))
 		return;
 
-	/* reset doesn't touch the display */
-	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+	drm_modeset_lock_all(dev);
+
+	/* reset doesn't touch the display, but flips might get nuked anyway, */
+	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
 		return;
 
-	drm_modeset_lock_all(dev);
+	ctx = dev->mode_config.acquire_ctx;
+
 	/*
 	 * Disabling the crtcs gracefully seems nicer. Also the
 	 * g33 docs say we should at least disable all the planes.
 	 */
-	intel_display_suspend(dev);
+
+	state = drm_atomic_helper_duplicate_state(dev, ctx);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
+		state = NULL;
+		DRM_ERROR("Duplicating state failed with %i\n", ret);
+		goto err;
+	}
+
+	ret = drm_atomic_helper_disable_all(dev, ctx);
+	if (ret) {
+		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
+		goto err;
+	}
+
+	dev_priv->modeset_restore_state = state;
+	state->acquire_ctx = ctx;
+	return;
+
+err:
+	drm_atomic_state_free(state);
 }
 
 void intel_finish_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = to_i915(dev);
+	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
+	int ret;
 
 	/*
 	 * Flips in the rings will be nuked by the reset,
@@ -3177,6 +3232,8 @@ void intel_finish_reset(struct drm_device *dev)
 	if (IS_GEN2(dev))
 		return;
 
+	dev_priv->modeset_restore_state = NULL;
+
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
 		/*
@@ -3189,26 +3246,27 @@ void intel_finish_reset(struct drm_device *dev)
 		 * CS-based flips (which might get lost in gpu resets) any more.
 		 */
 		intel_update_primary_planes(dev);
-		return;
-	}
-
-	/*
-	 * The display has been reset as well,
-	 * so need a full re-initialization.
-	 */
-	intel_runtime_pm_disable_interrupts(dev_priv);
-	intel_runtime_pm_enable_interrupts(dev_priv);
+	} else {
+		/*
+		 * The display has been reset as well,
+		 * so need a full re-initialization.
+		 */
+		intel_runtime_pm_disable_interrupts(dev_priv);
+		intel_runtime_pm_enable_interrupts(dev_priv);
 
-	intel_modeset_init_hw(dev);
+		intel_modeset_init_hw(dev);
 
-	spin_lock_irq(&dev_priv->irq_lock);
-	if (dev_priv->display.hpd_irq_setup)
-		dev_priv->display.hpd_irq_setup(dev);
-	spin_unlock_irq(&dev_priv->irq_lock);
+		spin_lock_irq(&dev_priv->irq_lock);
+		if (dev_priv->display.hpd_irq_setup)
+			dev_priv->display.hpd_irq_setup(dev);
+		spin_unlock_irq(&dev_priv->irq_lock);
 
-	intel_display_resume(dev);
+		ret = __intel_display_resume(dev, state);
+		if (ret)
+			DRM_ERROR("Restoring old state failed with %i\n", ret);
 
-	intel_hpd_init(dev_priv);
+		intel_hpd_init(dev_priv);
+	}
 
 	drm_modeset_unlock_all(dev);
 }
@@ -15955,9 +16013,10 @@ void intel_display_resume(struct drm_device *dev)
 	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
-	bool setup = false;
 
 	dev_priv->modeset_restore_state = NULL;
+	if (state)
+		state->acquire_ctx = &ctx;
 
 	/*
 	 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -15968,40 +16027,17 @@ void intel_display_resume(struct drm_device *dev)
 	mutex_lock(&dev->mode_config.mutex);
 	drm_modeset_acquire_init(&ctx, 0);
 
-retry:
-	ret = drm_modeset_lock_all_ctx(dev, &ctx);
-
-	if (ret == 0 && !setup) {
-		setup = true;
-
-		intel_modeset_setup_hw_state(dev);
-		i915_redisable_vga(dev);
-	}
-
-	if (ret == 0 && state) {
-		struct drm_crtc_state *crtc_state;
-		struct drm_crtc *crtc;
-		int i;
-
-		state->acquire_ctx = &ctx;
-
-		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			/*
-			 * Force recalculation even if we restore
-			 * current state. With fast modeset this may not result
-			 * in a modeset when the state is compatible.
-			 */
-			crtc_state->mode_changed = true;
-		}
-
-		ret = drm_atomic_commit(state);
-	}
+	while (1) {
+		ret = drm_modeset_lock_all_ctx(dev, &ctx);
+		if (ret != -EDEADLK)
+			break;
 
-	if (ret == -EDEADLK) {
 		drm_modeset_backoff(&ctx);
-		goto retry;
 	}
 
+	if (!ret)
+		ret = __intel_display_resume(dev, state);
+
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 	mutex_unlock(&dev->mode_config.mutex);
Signature · 7 lines
2.5.5


_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v3 1/2
#6 lore raw

Re: [PATCH v3 1/2] drm/i915: Fix modeset handling during gpu reset, v3.

Quoted 48 lines · Maarten Lankhorst

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 150 ++++++++++++++++++++++-------------
 1 file changed, 93 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/intel_display.c +9 -4
index 14e05091c397..6faa529f35df 100644
@@ -3130,41 +3130,96 @@ static void intel_update_primary_planes(struct drm_device *dev)
 
 	for_each_crtc(dev, crtc) {
 		struct intel_plane *plane = to_intel_plane(crtc->primary);
-		struct intel_plane_state *plane_state;
-
-		drm_modeset_lock_crtc(crtc, &plane->base);
-		plane_state = to_intel_plane_state(plane->base.state);
+		struct intel_plane_state *plane_state =
+			to_intel_plane_state(plane->base.state);
 
 		if (plane_state->visible)
 			plane->update_plane(&plane->base,
 					    to_intel_crtc_state(crtc->state),
 					    plane_state);
+	}
+}
+
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3155

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +8 -1
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i, ret;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
 
-		drm_modeset_unlock_crtc(crtc);
+	if (!state)
+		return 0;

Thank you diff for making things illegible.

I'm still not convinced we should be changing the locking scheme here, especially in what's supposed to be just a fix.

In general, I'm not sure we want ->detect() and other irrelevant stuff to block the GPU reset. The nice thing about g4x+ reset so far has been that it's almost unnoticeable. Of course if it's a genuine GPU hang the screen will probably have been frozen for quite a while when we initiate the reset, so perhaps that's not a huge real world issue.

Anyways, I kinda just want this fixed now, so I'll just toss in my

BTW as a followup I think we would actually want gen2 to take the g4x+ path. There won't have been a reset, but the flips in the ring will still never complete so our idea of frontbuffer may be out of sync with the hardware, and so we should fix it up.

Quoted 193 lines
drivers/gpu/drm/i915/intel_display.c +48 -5
+
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		/*
+		 * Force recalculation even if we restore
+		 * current state. With fast modeset this may not result
+		 * in a modeset when the state is compatible.
+		 */
+		crtc_state->mode_changed = true;
 	}
+
+	ret = drm_atomic_commit(state);
+
+	WARN_ON(ret == -EDEADLK);
+	return ret;
 }
 
 void intel_prepare_reset(struct drm_device *dev)
 {
+	struct drm_atomic_state *state;
+	struct drm_modeset_acquire_ctx *ctx;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	int ret;
+
 	/* no reset support for gen2 */
-	if (IS_GEN2(dev))
+	if (IS_GEN2(dev_priv))
 		return;
 
-	/* reset doesn't touch the display */
-	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+	drm_modeset_lock_all(dev);
 
 
+
+	/* reset doesn't touch the display, but flips might get nuked anyway, */
+	if (INTEL_INFO(dev_priv)->gen >= 5 || IS_G4X(dev_priv))
 		return;
 
-	drm_modeset_lock_all(dev);
+	ctx = dev->mode_config.acquire_ctx;
+
 	/*
 	 * Disabling the crtcs gracefully seems nicer. Also the
 	 * g33 docs say we should at least disable all the planes.
 	 */
-	intel_display_suspend(dev);
+
+	state = drm_atomic_helper_duplicate_state(dev, ctx);
+	if (IS_ERR(state)) {
+		ret = PTR_ERR(state);
+		state = NULL;
+		DRM_ERROR("Duplicating state failed with %i\n", ret);
+		goto err;
+	}
+
+	ret = drm_atomic_helper_disable_all(dev, ctx);
+	if (ret) {
+		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
+		goto err;
+	}
+
+	dev_priv->modeset_restore_state = state;
+	state->acquire_ctx = ctx;
+	return;
+
+err:
+	drm_atomic_state_free(state);
 }
 
 void intel_finish_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = to_i915(dev);
+	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
+	int ret;
 
drivers/gpu/drm/i915/intel_display.c +28 -47
 	/*
 	 * Flips in the rings will be nuked by the reset,
@@ -3177,6 +3232,8 @@ void intel_finish_reset(struct drm_device *dev)
 	if (IS_GEN2(dev))
 		return;
 
+	dev_priv->modeset_restore_state = NULL;
+
 	/* reset doesn't touch the display */
 	if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
 		/*
@@ -3189,26 +3246,27 @@ void intel_finish_reset(struct drm_device *dev)
 		 * CS-based flips (which might get lost in gpu resets) any more.
 		 */
 		intel_update_primary_planes(dev);
-		return;
-	}
-
-	/*
-	 * The display has been reset as well,
-	 * so need a full re-initialization.
-	 */
-	intel_runtime_pm_disable_interrupts(dev_priv);
-	intel_runtime_pm_enable_interrupts(dev_priv);
+	} else {
+		/*
+		 * The display has been reset as well,
+		 * so need a full re-initialization.
+		 */
+		intel_runtime_pm_disable_interrupts(dev_priv);
+		intel_runtime_pm_enable_interrupts(dev_priv);
 
-	intel_modeset_init_hw(dev);
+		intel_modeset_init_hw(dev);
 
-	spin_lock_irq(&dev_priv->irq_lock);
-	if (dev_priv->display.hpd_irq_setup)
-		dev_priv->display.hpd_irq_setup(dev);
-	spin_unlock_irq(&dev_priv->irq_lock);
+		spin_lock_irq(&dev_priv->irq_lock);
+		if (dev_priv->display.hpd_irq_setup)
+			dev_priv->display.hpd_irq_setup(dev);
+		spin_unlock_irq(&dev_priv->irq_lock);
 
-	intel_display_resume(dev);
+		ret = __intel_display_resume(dev, state);
+		if (ret)
+			DRM_ERROR("Restoring old state failed with %i\n", ret);
 
-	intel_hpd_init(dev_priv);
+		intel_hpd_init(dev_priv);
+	}
 
 	drm_modeset_unlock_all(dev);
 }
@@ -15955,9 +16013,10 @@ void intel_display_resume(struct drm_device *dev)
 	struct drm_atomic_state *state = dev_priv->modeset_restore_state;
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
-	bool setup = false;
 
 	dev_priv->modeset_restore_state = NULL;
+	if (state)
+		state->acquire_ctx = &ctx;
 
 	/*
 	 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -15968,40 +16027,17 @@ void intel_display_resume(struct drm_device *dev)
 	mutex_lock(&dev->mode_config.mutex);
 	drm_modeset_acquire_init(&ctx, 0);
 
-retry:
-	ret = drm_modeset_lock_all_ctx(dev, &ctx);
-
-	if (ret == 0 && !setup) {
-		setup = true;
-
-		intel_modeset_setup_hw_state(dev);
-		i915_redisable_vga(dev);
-	}
-
-	if (ret == 0 && state) {
-		struct drm_crtc_state *crtc_state;
-		struct drm_crtc *crtc;
-		int i;
-
-		state->acquire_ctx = &ctx;
-
-		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			/*
-			 * Force recalculation even if we restore
-			 * current state. With fast modeset this may not result
-			 * in a modeset when the state is compatible.
-			 */
-			crtc_state->mode_changed = true;
-		}
-
-		ret = drm_atomic_commit(state);
-	}
+	while (1) {
+		ret = drm_modeset_lock_all_ctx(dev, &ctx);
+		if (ret != -EDEADLK)
+			break;
 
-	if (ret == -EDEADLK) {
 		drm_modeset_backoff(&ctx);
-		goto retry;
 	}
 
+	if (!ret)
+		ret = __intel_display_resume(dev, state);
+
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 	mutex_unlock(&dev->mode_config.mutex);
Signature · 1 line
2.5.5
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [PATCH v3 1/2] drm/i915: Fix modeset handling during gpu reset, v3.

Quoted 65 lines · Ville Syrjälä
Quoted 48 lines · Maarten Lankhorst

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 150 ++++++++++++++++++++++-------------
 1 file changed, 93 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/intel_display.c +9 -4
index 14e05091c397..6faa529f35df 100644
@@ -3130,41 +3130,96 @@ static void intel_update_primary_planes(struct drm_device *dev)
 
 	for_each_crtc(dev, crtc) {
 		struct intel_plane *plane = to_intel_plane(crtc->primary);
-		struct intel_plane_state *plane_state;
-
-		drm_modeset_lock_crtc(crtc, &plane->base);
-		plane_state = to_intel_plane_state(plane->base.state);
+		struct intel_plane_state *plane_state =
+			to_intel_plane_state(plane->base.state);
 
 		if (plane_state->visible)
 			plane->update_plane(&plane->base,
 					    to_intel_crtc_state(crtc->state),
 					    plane_state);
+	}
+}
+
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3155

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +8 -1
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i, ret;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
 
-		drm_modeset_unlock_crtc(crtc);
+	if (!state)
+		return 0;

Thank you diff for making things illegible.

I'm still not convinced we should be changing the locking scheme here, especially in what's supposed to be just a fix.

Quoted 6 lines

In general, I'm not sure we want ->detect() and other irrelevant stuff to block the GPU reset. The nice thing about g4x+ reset so far has been that it's almost unnoticeable. Of course if it's a genuine GPU hang the screen will probably have been frozen for quite a while when we initiate the reset, so perhaps that's not a huge real world issue.

We don't really need dev->mode_config.mutex for atomic commits, so taking that out and use drm_modeset_lock_all_ctx would give you that. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Re: [PATCH v3 1/2] drm/i915: Fix modeset handling during gpu reset, v3.

Op 10-05-16 om 09:48 schreef Daniel Vetter:

Quoted 71 lines · Ville Syrjälä
Quoted 64 lines · Maarten Lankhorst
Quoted 48 lines

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 150 ++++++++++++++++++++++-------------
 1 file changed, 93 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/intel_display.c +9 -4
index 14e05091c397..6faa529f35df 100644
@@ -3130,41 +3130,96 @@ static void intel_update_primary_planes(struct drm_device *dev)
 
 	for_each_crtc(dev, crtc) {
 		struct intel_plane *plane = to_intel_plane(crtc->primary);
-		struct intel_plane_state *plane_state;
-
-		drm_modeset_lock_crtc(crtc, &plane->base);
-		plane_state = to_intel_plane_state(plane->base.state);
+		struct intel_plane_state *plane_state =
+			to_intel_plane_state(plane->base.state);
 
 		if (plane_state->visible)
 			plane->update_plane(&plane->base,
 					    to_intel_crtc_state(crtc->state),
 					    plane_state);
+	}
+}
+
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3155

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +8 -1
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i, ret;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
 
-		drm_modeset_unlock_crtc(crtc);
+	if (!state)
+		return 0;

Thank you diff for making things illegible.

I'm still not convinced we should be changing the locking scheme here, especially in what's supposed to be just a fix.

Quoted 6 lines

In general, I'm not sure we want ->detect() and other irrelevant stuff to block the GPU reset. The nice thing about g4x+ reset so far has been that it's almost unnoticeable. Of course if it's a genuine GPU hang the screen will probably have been frozen for quite a while when we initiate the reset, so perhaps that's not a huge real world issue.

Quoted 3 lines

We don't really need dev->mode_config.mutex for atomic commits, so taking that out and use drm_modeset_lock_all_ctx would give you that. -Daniel

Except that i915 still complains if we don't hold mode_config.mutex

commit ea49c9acf2db7082f0406bb3a570cc6bad37082b

Author: Maarten Lankhorst <[email protected]>
Date:   Tue Feb 16 15:27:42 2016 +0100

drm/i915: Lock mode_config.mutex in intel_display_resume.

So keeping it for now would be better.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

PATCH v3 1/2 drm/i915: Fix modeset handling during gpu reset, v4.

In reply to Daniel Vetter

Op 10-05-16 om 09:48 schreef Daniel Vetter:

Quoted 71 lines · Ville Syrjälä
Quoted 64 lines · Maarten Lankhorst
Quoted 48 lines

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/intel_display.c | 150 ++++++++++++++++++++++-------------
 1 file changed, 93 insertions(+), 57 deletions(-)
drivers/gpu/drm/i915/intel_display.c +9 -4
index 14e05091c397..6faa529f35df 100644
@@ -3130,41 +3130,96 @@ static void intel_update_primary_planes(struct drm_device *dev)
 
 	for_each_crtc(dev, crtc) {
 		struct intel_plane *plane = to_intel_plane(crtc->primary);
-		struct intel_plane_state *plane_state;
-
-		drm_modeset_lock_crtc(crtc, &plane->base);
-		plane_state = to_intel_plane_state(plane->base.state);
+		struct intel_plane_state *plane_state =
+			to_intel_plane_state(plane->base.state);
 
 		if (plane_state->visible)
 			plane->update_plane(&plane->base,
 					    to_intel_crtc_state(crtc->state),
 					    plane_state);
+	}
+}
+
+static int
+__intel_display_resume(struct drm_device *dev,
+		       struct drm_atomic_state *state)
+{

drivers/gpu/drm/i915/intel_display.c static void intel_update_primary_planes(struct drm_device *dev) · line 3155

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +8 -1
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int i, ret;
+
+	intel_modeset_setup_hw_state(dev);
+	i915_redisable_vga(dev);
 
-		drm_modeset_unlock_crtc(crtc);
+	if (!state)
+		return 0;

Thank you diff for making things illegible.

I'm still not convinced we should be changing the locking scheme here, especially in what's supposed to be just a fix.

Quoted 6 lines

In general, I'm not sure we want ->detect() and other irrelevant stuff to block the GPU reset. The nice thing about g4x+ reset so far has been that it's almost unnoticeable. Of course if it's a genuine GPU hang the screen will probably have been frozen for quite a while when we initiate the reset, so perhaps that's not a huge real world issue.

Quoted 3 lines

We don't really need dev->mode_config.mutex for atomic commits, so taking that out and use drm_modeset_lock_all_ctx would give you that. -Daniel

---->8----

This function would call drm_modeset_lock_all, while the suspend/resume functions already have their own locking. Fix this by factoring out __intel_display_resume, and calling the atomic helpers for duplicating atomic state and disabling all crtc's during suspend.

Changes since v1:
- Deal with -EDEADLK right after lock_all and clean up calls to hw readout.
- Always take all modeset locks so updates during gpu reset are blocked. Changes since v2:
- Fix deadlock in intel_update_primary_planes.
- Move WARN_ON(EDEADLK) to __intel_display_resume.
- pctx -> ctx
- only call __intel_display_resume on success in intel_display_resume. Changes since v3:
- Rebase on top of dev_priv -> dev change.
- Use drm_modeset_lock_all_ctx instead of drm_modeset_lock_all.

Fixes e2c8b8701e2d ("drm/i915: Use atomic helpers for suspend, v2.")
---
 drivers/gpu/drm/i915/i915_drv.h      |   1 +
 drivers/gpu/drm/i915/intel_display.c | 164 +++++++++++++++++++++++------------
 2 files changed, 109 insertions(+), 56 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 4abd39f32c0f..422e551937f7 100644
@@ -1835,6 +1835,7 @@ struct drm_i915_private {
 	enum modeset_restore modeset_restore;
 	struct mutex modeset_restore_lock;
 	struct drm_atomic_state *modeset_restore_state;
+	struct drm_modeset_acquire_ctx reset_ctx;
 
 	struct list_head vm_list; /* Global list of all address spaces */
 	struct i915_ggtt ggtt; /* VM representing the global address space */
drivers/gpu/drm/i915/intel_display.c +108 -56

231 lines not on this page · raw message

Signature · 7 lines
2.5.5


_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx