drm/i915: Eliminate race from gen2/3 page flip interrupt handling
Subsystems (2)
PATCH 1/1 drm/i915: Eliminate race from gen2/3 page flip interrupt handling
From: Ville Syrjälä <[email protected]>
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 complete too soon.
To eliminate this race check the live pending flip status from the ISR register before finishing the page flip.
--- drivers/gpu/drm/i915/i915_irq.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +15 -6
@@ -2284,8 +2284,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 0)) {if (iir &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,0 ); -intel_finish_page_flip (dev,0 ); - flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,0 ); + flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + } } }
@@ -2293,8 +2296,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 1)) {if (iir &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,1 ); -intel_finish_page_flip (dev,1 ); - flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,1 ); + flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + } } }
@@ -2491,8 +2497,11 @@ static irqreturn_t i915_irq_handler(int irq, void *arg) drm_handle_vblank(dev, pipe)) {if (iir & flip[plane]) {intel_prepare_page_flip (dev, plane); -intel_finish_page_flip (dev, pipe); - flip_mask &= ~flip[plane]; + +if ((I915_READ (ISR ) & flip[plane]) ==0 ) { +intel_finish_page_flip (dev, pipe); + flip_mask &= ~flip[plane]; + } } }
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Am Montag, den 18.02.2013, 13:57 +0200 schrieb [email protected]:
Quoted 5 lines
From: Ville Syrjälä <[email protected]>
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 complete too soon.
»would complete« or »would be complete*d*«
Quoted 2 lines
To eliminate this race check the live pending flip status from the ISR register before finishing the page flip.
Could this be tested somehow? Could a test case be written for this?
Quoted 38 lines
Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/i915_irq.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_irq.c +10
-4@@ -2284,8 +2284,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 0)) {if (iir &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,0 ); -intel_finish_page_flip (dev,0 ); - flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,0 ); + flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + } } }@@ -2293,8 +2296,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 1)) {if (iir &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,1 ); -intel_finish_page_flip (dev,1 ); - flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,1 ); + flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + } } }
drivers/gpu/drm/i915/i915_irq.c static irqreturn_t i915_irq_handler(int irq, void *arg) · line 2501
Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +2
-2@@ -2491,8 +2497,11 @@ static irqreturn_t i915_irq_handler(int irq, void *arg) drm_handle_vblank(dev, pipe)) {if (iir & flip[plane]) {intel_prepare_page_flip (dev, plane); -intel_finish_page_flip (dev, pipe); - flip_mask &= ~flip[plane]; + +if ((I915_READ (ISR ) & flip[plane]) ==0 ) {
Why not I915_READ16?
drivers/gpu/drm/i915/i915_irq.c static irqreturn_t i915_irq_handler(int irq, void *arg) · line 2506
Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3
-0+intel_finish_page_flip (dev, pipe); + flip_mask &= ~flip[plane]; + } } }
Thanks,
Paul
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 8 lines · Paul Menzel
Am Montag, den 18.02.2013, 13:57 +0200 schrieb [email protected]:
Quoted 5 lines
From: Ville Syrjälä <[email protected]>
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 complete too soon.
»would complete« or »would be complete*d*«
The second on is what I meant. Will fix.
Quoted 5 lines
Quoted 3 lines
To eliminate this race check the live pending flip status from the ISR register before finishing the page flip.
Could this be tested somehow? Could a test case be written for this?
It shouldn't be too difficult to force it from within the kernel. Just turn off interrupts before vblank start, wait until vblank start is passed, execute the MI_DISPLAY_FLIP, and finally turn the interrupts back on again.
Given the timing constraints I'm not sure we can come up with anything that would realiably hit it otherwise.
Quoted 38 lines
Quoted 38 lines
Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/i915/i915_irq.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_irq.c +10
-4@@ -2284,8 +2284,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 0)) {if (iir &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,0 ); -intel_finish_page_flip (dev,0 ); - flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,0 ); + flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT ; + } } }@@ -2293,8 +2296,11 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg) drm_handle_vblank(dev, 1)) {if (iir &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) {intel_prepare_page_flip (dev,1 ); -intel_finish_page_flip (dev,1 ); - flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + +if ((I915_READ16 (ISR ) &I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ) ==0 ) { +intel_finish_page_flip (dev,1 ); + flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT ; + } } }
Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c static irqreturn_t i915_irq_handler(int irq, void *arg) · line 2501
Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +2
-2@@ -2491,8 +2497,11 @@ static irqreturn_t i915_irq_handler(int irq, void *arg) drm_handle_vblank(dev, pipe)) {if (iir & flip[plane]) {intel_prepare_page_flip (dev, plane); -intel_finish_page_flip (dev, pipe); - flip_mask &= ~flip[plane]; + +if ((I915_READ (ISR ) & flip[plane]) ==0 ) {Why not
I915_READ16?
It matches the rest if i915_irq_handler(). I suppose the interrupt registers were 16 bit on gen2 and 32 bit on gen3+.
Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c static irqreturn_t i915_irq_handler(int irq, void *arg) · line 2506
Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +3
-0+intel_finish_page_flip (dev, pipe); + flip_mask &= ~flip[plane]; + } } }Thanks,
Paul
Signature · 2 lines
Ville Syrjälä Intel OTC
Quoted 8 lines · On Mon, Feb 18, 2013 at 01:57:51PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
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 complete too soon.
To eliminate this race check the live pending flip status from the ISR register before finishing the page flip.
Ok, that makes a lot of sense.
/* 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.
*/
Quoted 1 line
Signed-off-by Ville Syrjälä <[email protected]>
Time to give it a quick test and make sure it doesn't break a ton of assumptions... :)
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 10 lines · Chris Wilson
Quoted 8 lines · On Mon, Feb 18, 2013 at 01:57:51PM +0200, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
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 complete too soon.
To eliminate this race check the live pending flip status from the ISR register before finishing the page flip.
Quoted 8 lines
Ok, that makes a lot of sense.
/* 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 theMI_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.
*/
You want me to include that comment somewhere in the code?
Quoted 9 lines
Quoted 1 line
Signed-off-by Ville Syrjälä <[email protected]>Reviewed-by Chris Wilson <chris@chris-wilsTime to give it a quick test and make sure it doesn't break a ton of assumptions... :)
-ChrisSignature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Signature · 2 lines
Ville Syrjälä Intel OTC
Quoted 9 lines · Ville Syrjälä
Quoted 6 lines · Chris Wilson
/* 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 theMI_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.
*/You want me to include that comment somewhere in the code?
Please, would be useful for future archaeologists. I'd pick the gen3 location as it is more compact.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre