drm/i915: fix up semaphore_waits_for
Subsystems (2)
PATCH 1/2 drm/i915: fix up semaphore_waits_for
There's an entire pile of issues in here:
- Use the main RING_HEAD register, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100
--- drivers/gpu/drm/i915/i915_irq.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +26 -12
@@ -2529,29 +2529,43 @@ static struct intel_ring_buffer * semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) { struct drm_i915_private *dev_priv = ring->dev->dev_private; -u32 cmd, ipehr, acthd, acthd_min; +u32 cmd, ipehr, head; +int i; ipehr =I915_READ (RING_IPEHR (ring->mmio_base));if ((ipehr & ~(0x3 <<16 )) != (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE |MI_SEMAPHORE_REGISTER ))return NULL ; -/* ACTHD is likely pointing to the dword after the actual command, -* so scan backwards until we find the MBOX. +/* +* HEAD is likely pointing to the dword after the actual command, +* so scan backwards until we find the MBOX. But limit it to just 3 +* dwords. Note that we don't care about ACTHD here since that might +* point at at batch, and semaphores are always emitted into the +* ringbuffer itself. */ - acthd =intel_ring_get_active_head (ring) &HEAD_ADDR ; - acthd_min =max ((int )acthd -3 *4 ,0 ); -do { - cmd =ioread32 (ring->virtual_start + acthd); + head =I915_READ_HEAD (ring) &HEAD_ADDR ; + +for (i =4 ; i; --i) { +/* +* Be paranoid and presume the hw has gone off into the wild - +* our ring is smaller than what the hardware (and hence +* HEAD_ADDR) allows. Also handles wrap-around. +*/ + head &= ring->size -1 ; + +/* This here seems to blow up */ + cmd =ioread32 (ring->virtual_start + head);if (cmd == ipehr)break ; - acthd -=4 ; -if (acthd < acthd_min) -return NULL ; - }while (1 ); + head -=4 ; + } + +if (!i) +return NULL ; - *seqno =ioread32 (ring->virtual_start+acthd+4 )+1 ; + *seqno =ioread32 (ring->virtual_start + head +4 ) +1 ;return &dev_priv->ring[(ring->id + (((ipehr >>17 ) &1 ) +1 )) %3 ]; }
Signature · 1 line
1.8.1.4
PATCH 2/2 drm/i915: Add FIXME for bdw semaphore detection in hancheck
Currently not an issue since we don't emit sempahores, but better not forget about those.
As a little prep work extract the ipehr decoding for cleaner control flow. And apply a bit of polish.
--- drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +18 -2
@@ -2525,6 +2525,23 @@ ring_idle(struct intel_ring_buffer *ring, u32 seqno) i915_seqno_passed(seqno, ring_last_seqno(ring))); } +static bool +ipehr_is_semaphore_wait (struct drm_device *dev,u32 ipehr) +{ +if (INTEL_INFO (dev)->gen >=8 ) { +/* +* FIXME: gen8 semaphore support - currently we don't emit +* semaphores on bdw anyway, but this needs to be addressed when +* we merge that code. +*/ +return false; + }else { + ipehr &= ~MI_SEMAPHORE_SYNC_MASK ; +return ipehr == (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE | +MI_SEMAPHORE_REGISTER ); + } +} +static struct intel_ring_buffer *semaphore_waits_for (struct intel_ring_buffer *ring,u32 *seqno) {
@@ -2533,8 +2550,7 @@ semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)int i; ipehr =I915_READ (RING_IPEHR (ring->mmio_base)); -if ((ipehr & ~(0x3 <<16 )) != - (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE |MI_SEMAPHORE_REGISTER )) +if (!ipehr_is_semaphore_wait (ring->dev, ipehr))return NULL ;/*
drivers/gpu/drm/i915/i915_reg.h +2 -1
@@ -244,7 +244,8 @@#define MI_SEMAPHORE_SYNC_BVE (0<<16)/* VECS wait for BCS (VEBSYNC) */ #define MI_SEMAPHORE_SYNC_VVE (1<<16)/* VECS wait for VCS (VEVSYNC) */ #define MI_SEMAPHORE_SYNC_RVE (2<<16)/* VECS wait for RCS (VERSYNC) */ -#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_MASK (3<<16)#define MI_SET_CONTEXT MI_INSTR(0x18, 0)#define MI_MM_SPACE_GTT (1<<8)#define MI_MM_SPACE_PHYSICAL (0<<8)
Signature · 1 line
1.8.1.4
Re: [PATCH 2/2] drm/i915: Add FIXME for bdw semaphore detection in hancheck
Quoted 8 lines · Daniel Vetter
Currently not an issue since we don't emit sempahores, but better not forget about those.
As a little prep work extract the ipehr decoding for cleaner control flow. And apply a bit of polish.
Cc Ben Widawsky <[email protected]>Signed-off-by Daniel Vetter <[email protected]>
I've made a note to add the relevant BDW patch already.
one comment below.
Quoted 14 lines
--- drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/i915_irq.c +1
-0@@ -2525,6 +2525,23 @@ ring_idle(struct intel_ring_buffer *ring, u32 seqno) i915_seqno_passed(seqno, ring_last_seqno(ring))); } +static bool
drivers/gpu/drm/i915/i915_irq.c ring_idle(struct intel_ring_buffer *ring, u32 seqno) · line 2538
Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +10
-0+ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr) +{ + if (INTEL_INFO(dev)->gen >= 8) { + /* + * FIXME: gen8 semaphore support - currently we don't emit + * semaphores on bdw anyway, but this needs to be addressed when + * we merge that code. + */ + return false; + } else {
If you wanted to be paranoid:WARN_ON((ipehr & MI_SEMAPHORE_SYNC_MASK) == MI_SEMAPHORE_SYNC_INVALID)
Quoted 36 lines
drivers/gpu/drm/i915/i915_irq.c +7
-2+ ipehr &= ~MI_SEMAPHORE_SYNC_MASK ; +return ipehr == (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE | +MI_SEMAPHORE_REGISTER ); + } +} +static struct intel_ring_buffer *semaphore_waits_for (struct intel_ring_buffer *ring,u32 *seqno) {@@ -2533,8 +2550,7 @@ semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)int i; ipehr =I915_READ (RING_IPEHR (ring->mmio_base)); -if ((ipehr & ~(0x3 <<16 )) != - (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE |MI_SEMAPHORE_REGISTER )) +if (!ipehr_is_semaphore_wait (ring->dev, ipehr))return NULL ;/* drivers/gpu/drm/i915/i915_reg.h +2
-1@@ -244,7 +244,8 @@#define MI_SEMAPHORE_SYNC_BVE (0<<16)/* VECS wait for BCS (VEBSYNC) */ #define MI_SEMAPHORE_SYNC_VVE (1<<16)/* VECS wait for VCS (VEVSYNC) */ #define MI_SEMAPHORE_SYNC_RVE (2<<16)/* VECS wait for RCS (VERSYNC) */ -#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_MASK (3<<16)#define MI_SET_CONTEXT MI_INSTR(0x18, 0)#define MI_MM_SPACE_GTT (1<<8)#define MI_MM_SPACE_PHYSICAL (0<<8)Signature · 1 line
1.8.1.4
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Re: [PATCH 2/2] drm/i915: Add FIXME for bdw semaphore detection in hancheck
Quoted 7 lines · Ben Widawsky
Quoted 6 lines · Daniel Vetter
Currently not an issue since we don't emit sempahores, but better not forget about those.
As a little prep work extract the ipehr decoding for cleaner control flow. And apply a bit of polish.
Quoted 6 lines
Quoted 2 lines
Cc Ben Widawsky <[email protected]>Signed-off-by Daniel Vetter <[email protected]>Reviewed-by Ben Widawsky <[email protected]>I've made a note to add the relevant BDW patch already.
Thanks. I'll pull it in as soon as the previous bugfix patch is reviewed by Mika/Chris. Btw I've almost written the bdw patch myself (it's just two lines or so + adjusting the number of dwords we scan back) but then realized that the #defines I'm adding will needlessly conflict with your series, so let it be.
Quoted 14 lines
one comment below.
Quoted 13 lines
--- drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/i915_irq.c +0
-0@@ -2525,6 +2525,23 @@ ring_idle(struct intel_ring_buffer *ring, u32 seqno) i915_seqno_passed(seqno, ring_last_seqno(ring))); }
Quoted 14 lines
drivers/gpu/drm/i915/i915_irq.c ring_idle(struct intel_ring_buffer *ring, u32 seqno) · line 2538
Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +11
-0+static bool +ipehr_is_semaphore_wait (struct drm_device *dev,u32 ipehr) +{ +if (INTEL_INFO (dev)->gen >=8 ) { +/* +* FIXME: gen8 semaphore support - currently we don't emit +* semaphores on bdw anyway, but this needs to be addressed when +* we merge that code. +*/ +return false; + }else {If you wanted to be paranoid:
WARN_ON((ipehr & MI_SEMAPHORE_SYNC_MASK) == MI_SEMAPHORE_SYNC_INVALID)
Good idea but wrong spot. At the end of semaphore_waits_for we use the SYNC_MASK to compute the ring pointer of the signaller. That's completely unchecked code (and full of magic stuff). I'll throw another patch on top to extract this and add a few paranoid checks in the spirit of your suggestion above.
Cheers, Daniel
Quoted 40 lines
Quoted 37 lines
drivers/gpu/drm/i915/i915_irq.c +7
-2+ ipehr &= ~MI_SEMAPHORE_SYNC_MASK ; +return ipehr == (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE | +MI_SEMAPHORE_REGISTER ); + } +} +static struct intel_ring_buffer *semaphore_waits_for (struct intel_ring_buffer *ring,u32 *seqno) {@@ -2533,8 +2550,7 @@ semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)int i; ipehr =I915_READ (RING_IPEHR (ring->mmio_base)); -if ((ipehr & ~(0x3 <<16 )) != - (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE |MI_SEMAPHORE_REGISTER )) +if (!ipehr_is_semaphore_wait (ring->dev, ipehr))return NULL ;/* drivers/gpu/drm/i915/i915_reg.h +2
-1@@ -244,7 +244,8 @@#define MI_SEMAPHORE_SYNC_BVE (0<<16)/* VECS wait for BCS (VEBSYNC) */ #define MI_SEMAPHORE_SYNC_VVE (1<<16)/* VECS wait for VCS (VEVSYNC) */ #define MI_SEMAPHORE_SYNC_RVE (2<<16)/* VECS wait for RCS (VERSYNC) */ -#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_INVALID (3<<16) +#define MI_SEMAPHORE_SYNC_MASK (3<<16)#define MI_SET_CONTEXT MI_INSTR(0x18, 0)#define MI_MM_SPACE_GTT (1<<8)#define MI_MM_SPACE_PHYSICAL (0<<8)Signature · 1 line
1.8.1.4Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 1/1 drm/i915: make semaphore signaller detection more robust
Extract all this logic into a new helper function semaphore_wait_to_signaller_ring because:
- The current code has way too much magic.
- The current code doesn't look at bi16, which encodes VECS signallers on HSW. Those are just added after the fact, so can't be encoded in a neat formula.
- It blindly trust the hardware for the dev_priv->ring array derefence, which given that we have a gpu hang at hand is scary. The current logic can't blow up since it limits its value range sufficiently, but that's a bit too tricky to rely on in my opinion. Especially when we start to add bdw support.
- I'm not a big fan of the explicit ring->semaphore_register list, but I think it's more robust to use the same mapping both when constructing the semaphore commands and when decoding them.
- Finally add a FIXME comment about lack of broadwell support here, like in the earlier ipehr semaphore cmd detection function.
--- drivers/gpu/drm/i915/i915_irq.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_irq.c +34 -1
@@ -2543,6 +2543,39 @@ ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr) }static struct intel_ring_buffer * +semaphore_wait_to_signaller_ring (struct intel_ring_buffer *ring,u32 ipehr) +{ +struct drm_i915_private *dev_priv = ring->dev->dev_private; +struct intel_ring_buffer *signaller; +int i; + +if (INTEL_INFO (dev_priv->dev)->gen >=8 ) { +/* +* FIXME: gen8 semaphore support - currently we don't emit +* semaphores on bdw anyway, but this needs to be addressed when +* we merge that code. +*/ +return NULL ; + }else { +u32 sync_bits = ipehr &MI_SEMAPHORE_SYNC_MASK ; + +for_each_ring (signaller, dev_priv, i) { +if (ring == signaller) +continue ; + +if (sync_bits == + signaller->semaphore_register[ring->id]) +return signaller; + } + } + +DRM_ERROR ("No signaller ring found for ring %i, ipehr 0x%08x\n" , + ring->id, ipehr); + +return NULL ; +} + +static struct intel_ring_buffer *semaphore_waits_for (struct intel_ring_buffer *ring,u32 *seqno) {struct drm_i915_private *dev_priv = ring->dev->dev_private;
@@ -2582,7 +2615,7 @@ semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)return NULL ; *seqno =ioread32 (ring->virtual_start + head +4 ) +1 ; -return &dev_priv->ring[(ring->id + (((ipehr >>17 ) &1 ) +1 )) %3 ]; +return semaphore_wait_to_signaller_ring (ring, ipehr); }static int semaphore_passed (struct intel_ring_buffer *ring)
Signature · 1 line
1.8.1.4
Re: [PATCH] drm/i915: make semaphore signaller detection more robust
Quoted 9 lines · Daniel Vetter
Extract all this logic into a new helper function
semaphore_wait_to_signaller_ringbecause:- The current code has way too much magic.
- The current code doesn't look at bi16, which encodes VECS signallers on HSW. Those are just added after the fact, so can't be encoded in a neat formula.
Quoted 5 lines
- It blindly trust the hardware for the
dev_priv->ringarray derefence, which given that we have a gpu hang at hand is scary. The current logic can't blow up since it limits its value range sufficiently, but that's a bit too tricky to rely on in my opinion. Especially when we start to add bdw support.
No, it does not blindly trust. What you just mean here is that to extend it for hsw+ it is simpler to reimplement differently.
Quoted 11 lines
- I'm not a big fan of the explicit
ring->semaphore_registerlist, but I think it's more robust to use the same mapping both when constructing the semaphore commands and when decoding them.- Finally add a FIXME comment about lack of broadwell support here, like in the earlier ipehr semaphore cmd detection function.
Cc Mika Kuoppala <[email protected]>Cc Ben Widawsky <[email protected]>Cc Chris Wilson <[email protected]>Signed-off-by Daniel Vetter <[email protected]>
Other than the digression above, where did MI_SEMAPHORE_SYNC_MASK spring from? Early patch?
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH] drm/i915: make semaphore signaller detection more robust
Quoted 10 lines · Chris Wilson
Quoted 9 lines · Daniel Vetter
Extract all this logic into a new helper function
semaphore_wait_to_signaller_ringbecause:- The current code has way too much magic.
- The current code doesn't look at bi16, which encodes VECS signallers on HSW. Those are just added after the fact, so can't be encoded in a neat formula.
Quoted 8 lines
Quoted 5 lines
- It blindly trust the hardware for the
dev_priv->ringarray derefence, which given that we have a gpu hang at hand is scary. The current logic can't blow up since it limits its value range sufficiently, but that's a bit too tricky to rely on in my opinion. Especially when we start to add bdw support.No, it does not blindly trust. What you just mean here is that to extend it for hsw+ it is simpler to reimplement differently.
Note that I say that the current logic can't blow up due to the limited value range ... I can drop the "blindly trust" and leave it at "too tricky" when merging.
Quoted 7 lines
Quoted 7 lines
- I'm not a big fan of the explicit
ring->semaphore_registerlist, but I think it's more robust to use the same mapping both when constructing the semaphore commands and when decoding them.- Finally add a FIXME comment about lack of broadwell support here, like in the earlier ipehr semaphore cmd detection function.
Quoted 7 lines
Quoted 4 lines
Cc Mika Kuoppala <[email protected]>Cc Ben Widawsky <[email protected]>Cc Chris Wilson <[email protected]>Signed-off-by Daniel Vetter <[email protected]>Other than the digression above, where did
MI_SEMAPHORE_SYNC_MASKspring from? Early patch?
Yeah, the two patches this one here should be in-reply-to have that #define. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.
True, nice catch that would explain a hard hang quite neatly if we tried to read from beyond the aperture.
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
You can ignore ring wrapping as valid commands cannot wrap, hence the formulation of acthd_min.
/*
* Be paranoid and presume the hw has gone off into the wild -
* our ring is smaller than what the hardware (and hence
* HEAD_ADDR) allows.
*/
head = I915_READ_HEAD(ring) & (ring->size - 1); head_min = max((int)head - 3 * 4, 0);
while (head >= head_min) {
cmd = ioread32(ring->virtual_start + head);
if (cmd == ipehr)
break;
head -= 4;}
drivers/gpu/drm/i915/i915_irq.c static struct intel_ring_buffer * · line 2558
Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +9
-0+/* +* Be paranoid and presume the hw has gone off into the wild - +* our ring is smaller than what the hardware (and hence +* HEAD_ADDR) allows. Also handles wrap-around. +*/ + head &= ring->size -1 ; + +/* This here seems to blow up */ + cmd =ioread32 (ring->virtual_start + head);
So what does this mean?
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 19 lines · Chris Wilson
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.True, nice catch that would explain a hard hang quite neatly if we tried to read from beyond the aperture.
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 6 lines
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
You can ignore ring wrapping as valid commands cannot wrap, hence the formulation of
acthd_min.
Well I've thought that HEAD usually points at the next command. I'm not sure about the exact semantics at wrap-around time but since implementing it was trivially I've figured it's better to be paranoid.
Quoted 7 lines
/*
* Be paranoid and presume the hw has gone off into the wild -
* our ring is smaller than what the hardware (and hence
*HEAD_ADDR) allows.
*/
head =I915_READ_HEAD(ring)& (ring->size- 1);head_min=max((int)head - 3 * 4, 0);
Quoted 6 lines
while (head >= head_min) { cmd = ioread32(ring->virtual_start + head); if (cmd == ipehr) break; head -= 4;}
Yeah, this would also fix the immediate bug at hand. But my general impression of this code is that it's trusting reconstructed state way too much. Hence why I've gone for the more wordy version of firsting oring out the right field from the register and then for restricting with the size of the ring. I'll do a follow-up patch to give the the same treatment to the semaphore signaller computation.
Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c static struct intel_ring_buffer * · line 2558
Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +9
-0+/* +* Be paranoid and presume the hw has gone off into the wild - +* our ring is smaller than what the hardware (and hence +* HEAD_ADDR) allows. Also handles wrap-around. +*/ + head &= ring->size -1 ; + +/* This here seems to blow up */ + cmd =ioread32 (ring->virtual_start + head);So what does this mean?
Oops, the comment was just a note from my oops decoding. The ioread32 is where we've blown. The comment should be removed since it's not useful outside of my debug session.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 24 lines · Daniel Vetter
Quoted 23 lines · Chris Wilson
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.True, nice catch that would explain a hard hang quite neatly if we tried to read from beyond the aperture.
Quoted 12 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
Quoted 6 lines
Quoted 2 lines
You can ignore ring wrapping as valid commands cannot wrap, hence the formulation of
acthd_min.Well I've thought that HEAD usually points at the next command. I'm not sure about the exact semantics at wrap-around time but since implementing it was trivially I've figured it's better to be paranoid.
Nah, it points to ring->size upon parsing a command that exactly ends upon the wrap around, But your point stands.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Hi,
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.
The ipehr check should make sure that we are at the ring and acthd should not be at batch.
Regardless I agree that RING_HEAD is much more safer. When I have tried to get bottom of the snb reset hang, I have noticed that after reset the acthd is sometimes 0x0c even tho head is 0x00, on snb.
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
ipehr dont update on MI_NOOPS and the head should point to the extra MI_NOOP after semaphore sequence. So 4 should be enough. Perhaps revisit this when bdw gains semaphores.
Quoted 9 lines
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100
The hard hangs are not so frequent with this patch but they are still there. This patch should take care of the oops we have been seeing, but there is still something else to be found until #74100 can be marked as fixed.
Very often after reset, when igt has pushed the quietence batches into rings, blitter and video ring heads gets moved properly but all updates to hardware status page and to the sync registers are missing. And result is hang by hangcheck. Repeat enough times and it is a hard hang.
Quoted 1 line
Signed-off-by Daniel Vetter <[email protected]>
Please remove the blowup comment and also update the bugzilla tag.
Patches 1-2 and the followup one are
Quoted 66 lines
--- drivers/gpu/drm/i915/i915_irq.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)drivers/gpu/drm/i915/i915_irq.c +26
-12@@ -2529,29 +2529,43 @@ static struct intel_ring_buffer * semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) { struct drm_i915_private *dev_priv = ring->dev->dev_private; -u32 cmd, ipehr, acthd, acthd_min; +u32 cmd, ipehr, head; +int i; ipehr =I915_READ (RING_IPEHR (ring->mmio_base));if ((ipehr & ~(0x3 <<16 )) != (MI_SEMAPHORE_MBOX |MI_SEMAPHORE_COMPARE |MI_SEMAPHORE_REGISTER ))return NULL ; -/* ACTHD is likely pointing to the dword after the actual command, -* so scan backwards until we find the MBOX. +/* +* HEAD is likely pointing to the dword after the actual command, +* so scan backwards until we find the MBOX. But limit it to just 3 +* dwords. Note that we don't care about ACTHD here since that might +* point at at batch, and semaphores are always emitted into the +* ringbuffer itself. */ - acthd =intel_ring_get_active_head (ring) &HEAD_ADDR ; - acthd_min =max ((int )acthd -3 *4 ,0 ); -do { - cmd =ioread32 (ring->virtual_start + acthd); + head =I915_READ_HEAD (ring) &HEAD_ADDR ; + +for (i =4 ; i; --i) { +/* +* Be paranoid and presume the hw has gone off into the wild - +* our ring is smaller than what the hardware (and hence +* HEAD_ADDR) allows. Also handles wrap-around. +*/ + head &= ring->size -1 ; + +/* This here seems to blow up */ + cmd =ioread32 (ring->virtual_start + head);if (cmd == ipehr)break ; - acthd -=4 ; -if (acthd < acthd_min) -return NULL ; - }while (1 ); + head -=4 ; + } + +if (!i) +return NULL ; - *seqno =ioread32 (ring->virtual_start+acthd+4 )+1 ; + *seqno =ioread32 (ring->virtual_start + head +4 ) +1 ;return &dev_priv->ring[(ring->id + (((ipehr >>17 ) &1 ) +1 )) %3 ]; }Signature · 1 line
1.8.1.4
Quoted 10 lines · Mika Kuoppala
Hi,
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.
Quoted 7 lines
The ipehr check should make sure that we are at the ring and acthd should not be at batch.
Regardless I agree that
RING_HEADis much more safer. When I have tried to get bottom of the snb reset hang, I have noticed that after reset the acthd is sometimes0x0ceven tho head is0x00, on snb.
Hm, should we maybe mask out the lower bits, too? If you can confirm this, can you please add a follow-up patch?
Quoted 9 lines
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 7 lines
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
ipehr dont update on
MI_NOOPSand the head should point to the extraMI_NOOPafter semaphore sequence. So 4 should be enough. Perhaps revisit this when bdw gains semaphores.
Yeah, Chris also mentioned that the HEAD should point at one dword past the end of the ring, so should even work when there are no MI_NOOPs. In any case this code is more robust in case hw engineers suddenly change the behaviour.
Quoted 22 lines
Quoted 9 lines
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100The hard hangs are not so frequent with this patch but they are still there. This patch should take care of the oops we have been seeing, but there is still something else to be found until #74100 can be marked as fixed.
Very often after reset, when igt has pushed the quietence batches into rings, blitter and video ring heads gets moved properly but all updates to hardware status page and to the sync registers are missing. And result is hang by hangcheck. Repeat enough times and it is a hard hang.
Quoted 4 lines
Quoted 1 line
Signed-off-by Daniel Vetter <[email protected]>Please remove the blowup comment and also update the bugzilla tag.
Yeah, QA also says that it doesn't fix the hard hangs, only seems to reduce them a bit on certain setups. I've updated the commit message.
btw are you testing with FBDEV=n? The lack of a fbcon panic handler should greatly increase the chances that the last few message get correctly transmitted through other means like netconsole.
Quoted 3 lines
Patches 1-2 and the followup one are
Reviewed-by Mika Kuoppala <[email protected]>
Thanks for the review, patches merged.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 78 lines · Daniel Vetter
Quoted 10 lines · Mika Kuoppala
Hi,
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.Quoted 7 lines
The ipehr check should make sure that we are at the ring and acthd should not be at batch.
Regardless I agree that
RING_HEADis much more safer. When I have tried to get bottom of the snb reset hang, I have noticed that after reset the acthd is sometimes0x0ceven tho head is0x00, on snb.Hm, should we maybe mask out the lower bits, too? If you can confirm this, can you please add a follow-up patch?
Quoted 9 lines
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 7 lines
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
ipehr dont update on
MI_NOOPSand the head should point to the extraMI_NOOPafter semaphore sequence. So 4 should be enough. Perhaps revisit this when bdw gains semaphores.Yeah, Chris also mentioned that the HEAD should point at one dword past the end of the ring, so should even work when there are no
MI_NOOPs. In any case this code is more robust in case hw engineers suddenly change the behaviour.Quoted 22 lines
Quoted 9 lines
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100The hard hangs are not so frequent with this patch but they are still there. This patch should take care of the oops we have been seeing, but there is still something else to be found until #74100 can be marked as fixed.
Very often after reset, when igt has pushed the quietence batches into rings, blitter and video ring heads gets moved properly but all updates to hardware status page and to the sync registers are missing. And result is hang by hangcheck. Repeat enough times and it is a hard hang.
Quoted 4 lines
Quoted 1 line
Signed-off-by Daniel Vetter <[email protected]>Please remove the blowup comment and also update the bugzilla tag.
Yeah, QA also says that it doesn't fix the hard hangs, only seems to reduce them a bit on certain setups. I've updated the commit message.
btw are you testing with FBDEV=n? The lack of a fbcon panic handler should greatly increase the chances that the last few message get correctly transmitted through other means like netconsole.
Quoted 6 lines
Quoted 3 lines
Patches 1-2 and the followup one are
Reviewed-by Mika Kuoppala <[email protected]>Thanks for the review, patches merged.
-Daniel
Patch 2 was trivial to implement for gen8. This functionality is a lot less trivial. I volunteered to do patch 2, are you going to port this to gen8?
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Quoted 81 lines · Ben Widawsky
Quoted 80 lines · Daniel Vetter
Quoted 10 lines · Mika Kuoppala
Hi,
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.Quoted 7 lines
The ipehr check should make sure that we are at the ring and acthd should not be at batch.
Regardless I agree that
RING_HEADis much more safer. When I have tried to get bottom of the snb reset hang, I have noticed that after reset the acthd is sometimes0x0ceven tho head is0x00, on snb.Hm, should we maybe mask out the lower bits, too? If you can confirm this, can you please add a follow-up patch?
Quoted 9 lines
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 7 lines
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
ipehr dont update on
MI_NOOPSand the head should point to the extraMI_NOOPafter semaphore sequence. So 4 should be enough. Perhaps revisit this when bdw gains semaphores.Yeah, Chris also mentioned that the HEAD should point at one dword past the end of the ring, so should even work when there are no
MI_NOOPs. In any case this code is more robust in case hw engineers suddenly change the behaviour.Quoted 22 lines
Quoted 9 lines
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100The hard hangs are not so frequent with this patch but they are still there. This patch should take care of the oops we have been seeing, but there is still something else to be found until #74100 can be marked as fixed.
Very often after reset, when igt has pushed the quietence batches into rings, blitter and video ring heads gets moved properly but all updates to hardware status page and to the sync registers are missing. And result is hang by hangcheck. Repeat enough times and it is a hard hang.
Quoted 4 lines
Quoted 1 line
Signed-off-by Daniel Vetter <[email protected]>Please remove the blowup comment and also update the bugzilla tag.
Yeah, QA also says that it doesn't fix the hard hangs, only seems to reduce them a bit on certain setups. I've updated the commit message.
btw are you testing with FBDEV=n? The lack of a fbcon panic handler should greatly increase the chances that the last few message get correctly transmitted through other means like netconsole.
Quoted 2 lines
Patches 1-2 and the followup one are
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Mika Kuoppala <[email protected]>Thanks for the review, patches merged.
-DanielPatch 2 was trivial to implement for gen8. This functionality is a lot less trivial. I volunteered to do patch 2, are you going to port this to gen8?
If you fill out the bdw pieces for patch 2&3 the only thing you need to change here is to adjsut the number of dwords we walk backwards to make sure that the bdw semaphore cmd still fits. Or at least that's been my idea behind all this, maybe I've overlooked something. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 91 lines · Daniel Vetter
Quoted 81 lines · Ben Widawsky
Quoted 80 lines · Daniel Vetter
Quoted 10 lines · Mika Kuoppala
Hi,
Quoted 5 lines · Daniel Vetter
There's an entire pile of issues in here:
- Use the main
RING_HEADregister, not ACTHD. ACTHD points at the gtt offset of the batch buffer when a batch is executed. Semaphores are always emitted to the main ring, so we always want to look at that.Quoted 7 lines
The ipehr check should make sure that we are at the ring and acthd should not be at batch.
Regardless I agree that
RING_HEADis much more safer. When I have tried to get bottom of the snb reset hang, I have noticed that after reset the acthd is sometimes0x0ceven tho head is0x00, on snb.Hm, should we maybe mask out the lower bits, too? If you can confirm this, can you please add a follow-up patch?
Quoted 9 lines
Quoted 9 lines
- Mask the obtained HEAD pointer with the actual ring size, which is much smaller. Together with the above issue this resulted us in trying to dereference a pointer way outside of the ring mmio mapping. The resulting invalid access in interrupt context (hangcheck is executed from timers) lead to a full blown kernel panic. The fbcon panic handler then tried to frob our driver harder, resulting in a full machine hang at least on my snb here where I've stumbled over this.
Quoted 7 lines
Quoted 3 lines
- Handle ring wrapping correctly and be a bit more explicit about how many dwords we're scanning. We probably should also scan more than just 4 ...
ipehr dont update on
MI_NOOPSand the head should point to the extraMI_NOOPafter semaphore sequence. So 4 should be enough. Perhaps revisit this when bdw gains semaphores.Yeah, Chris also mentioned that the HEAD should point at one dword past the end of the ring, so should even work when there are no
MI_NOOPs. In any case this code is more robust in case hw engineers suddenly change the behaviour.Quoted 22 lines
Quoted 9 lines
- Space out some of teh computations for readability.
This prevents hard-hangs on my snb here. Verdict from QA is still pending, but the symptoms match.
Cc: Mika Kuoppala <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Chris Wilson <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=74100The hard hangs are not so frequent with this patch but they are still there. This patch should take care of the oops we have been seeing, but there is still something else to be found until #74100 can be marked as fixed.
Very often after reset, when igt has pushed the quietence batches into rings, blitter and video ring heads gets moved properly but all updates to hardware status page and to the sync registers are missing. And result is hang by hangcheck. Repeat enough times and it is a hard hang.
Quoted 4 lines
Quoted 1 line
Signed-off-by Daniel Vetter <[email protected]>Please remove the blowup comment and also update the bugzilla tag.
Yeah, QA also says that it doesn't fix the hard hangs, only seems to reduce them a bit on certain setups. I've updated the commit message.
btw are you testing with FBDEV=n? The lack of a fbcon panic handler should greatly increase the chances that the last few message get correctly transmitted through other means like netconsole.
Quoted 2 lines
Patches 1-2 and the followup one are
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Mika Kuoppala <[email protected]>Thanks for the review, patches merged.
-DanielPatch 2 was trivial to implement for gen8. This functionality is a lot less trivial. I volunteered to do patch 2, are you going to port this to gen8?
Quoted 5 lines
If you fill out the bdw pieces for patch 2&3 the only thing you need to change here is to adjsut the number of dwords we walk backwards to make sure that the bdw semaphore cmd still fits. Or at least that's been my idea behind all this, maybe I've overlooked something. -Daniel
I don't think it's quite that easy, but I took it as a, "yes." Which one is patch 3?
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Quoted 2 lines · Ben Widawsky
I don't think it's quite that easy, but I took it as a, "yes." Which one is patch 3?
"drm/i915: make semaphore signaller detection more robust" - it was a follow-up patch in this thread, hence no 3/3. If the relevant bits on bdw have moved out of the the cmd dword I guess we need to keep a cache of the relevant dword and supply it to the function. Was too lazy to check that though.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch