Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e2032d4 authored by Ville Syrjälä's avatar Ville Syrjälä Committed by Daniel Vetter
Browse files

drm/i915: Eliminate race from gen2/3 page flip interrupt handling



If the interrupt handler were to process a previous vblank interrupt and
the following flip pending interrupt at the same time, the page flip
would be completed too soon.

To eliminate this race, check the live pending flip status from the ISR
register before finishing the page flip.

v2: Added a comment explaining the logic (by Chris Wilson)
v3: Fix a typo in the comment

Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Tested-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 2ec90668
Loading
Loading
Loading
Loading
+21 −6
Original line number Original line Diff line number Diff line
@@ -2284,19 +2284,25 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
		    drm_handle_vblank(dev, 0)) {
		    drm_handle_vblank(dev, 0)) {
			if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
			if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
				intel_prepare_page_flip(dev, 0);
				intel_prepare_page_flip(dev, 0);

				if ((I915_READ16(ISR) & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) == 0) {
					intel_finish_page_flip(dev, 0);
					intel_finish_page_flip(dev, 0);
					flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT;
					flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT;
				}
				}
			}
			}
		}


		if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
		if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
		    drm_handle_vblank(dev, 1)) {
		    drm_handle_vblank(dev, 1)) {
			if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
			if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
				intel_prepare_page_flip(dev, 1);
				intel_prepare_page_flip(dev, 1);

				if ((I915_READ16(ISR) & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) == 0) {
					intel_finish_page_flip(dev, 1);
					intel_finish_page_flip(dev, 1);
					flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
					flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
				}
				}
			}
			}
		}


		iir = new_iir;
		iir = new_iir;
	}
	}
@@ -2491,10 +2497,19 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
			    drm_handle_vblank(dev, pipe)) {
			    drm_handle_vblank(dev, pipe)) {
				if (iir & flip[plane]) {
				if (iir & flip[plane]) {
					intel_prepare_page_flip(dev, plane);
					intel_prepare_page_flip(dev, plane);

					/* We detect FlipDone by looking for the change in PendingFlip from '1'
					 * to '0' on the following vblank, i.e. IIR has the Pendingflip
					 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
					 * the flip is completed (no longer pending). Since this doesn't raise an
					 * interrupt per se, we watch for the change at vblank.
					 */
					if ((I915_READ(ISR) & flip[plane]) == 0) {
						intel_finish_page_flip(dev, pipe);
						intel_finish_page_flip(dev, pipe);
						flip_mask &= ~flip[plane];
						flip_mask &= ~flip[plane];
					}
					}
				}
				}
			}


			if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
			if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
				blc_event = true;
				blc_event = true;