aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2018-06-10 15:43:09 -0400
committerJani Nikula <jani.nikula@intel.com>2018-06-19 08:47:37 -0400
commit7ba33e1c9d1e03f442b161c701d1f811ea13c75e (patch)
tree3ae98b64efd0dbf9fc7a3c2ec2243ffda897bbf2
parentce397d215ccd07b8ae3f71db689aedb85d56ab40 (diff)
drm/i915: Apply batch location restrictions before pinning
We special case the position of the batch within the GTT to prevent negative self-relocation deltas from underflowing. However, that restriction is being applied after a trial pin of the batch in its current position. Thus we are not rejecting an invalid location if the batch has been used before, leading to an assertion if we happen to need to rearrange the entire payload. In the worst case, this may cause a GPU hang on gen7 or perhaps missing state. References: https://bugs.freedesktop.org/show_bug.cgi?id=105720 Fixes: 2889caa92321 ("drm/i915: Eliminate lots of iterations over the execobjects array") Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Martin Peres <martin.peres@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180610194325.13467-2-chris@chris-wilson.co.uk Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> (cherry picked from commit 746c8f143afad7aaa66c484485fc39888d437a3f) Signed-off-by: Jani Nikula <jani.nikula@intel.com>
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index f627a8c47c58..22df17c8ca9b 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -489,7 +489,9 @@ eb_validate_vma(struct i915_execbuffer *eb,
489} 489}
490 490
491static int 491static int
492eb_add_vma(struct i915_execbuffer *eb, unsigned int i, struct i915_vma *vma) 492eb_add_vma(struct i915_execbuffer *eb,
493 unsigned int i, unsigned batch_idx,
494 struct i915_vma *vma)
493{ 495{
494 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; 496 struct drm_i915_gem_exec_object2 *entry = &eb->exec[i];
495 int err; 497 int err;
@@ -522,6 +524,24 @@ eb_add_vma(struct i915_execbuffer *eb, unsigned int i, struct i915_vma *vma)
522 eb->flags[i] = entry->flags; 524 eb->flags[i] = entry->flags;
523 vma->exec_flags = &eb->flags[i]; 525 vma->exec_flags = &eb->flags[i];
524 526
527 /*
528 * SNA is doing fancy tricks with compressing batch buffers, which leads
529 * to negative relocation deltas. Usually that works out ok since the
530 * relocate address is still positive, except when the batch is placed
531 * very low in the GTT. Ensure this doesn't happen.
532 *
533 * Note that actual hangs have only been observed on gen7, but for
534 * paranoia do it everywhere.
535 */
536 if (i == batch_idx) {
537 if (!(eb->flags[i] & EXEC_OBJECT_PINNED))
538 eb->flags[i] |= __EXEC_OBJECT_NEEDS_BIAS;
539 if (eb->reloc_cache.has_fence)
540 eb->flags[i] |= EXEC_OBJECT_NEEDS_FENCE;
541
542 eb->batch = vma;
543 }
544
525 err = 0; 545 err = 0;
526 if (eb_pin_vma(eb, entry, vma)) { 546 if (eb_pin_vma(eb, entry, vma)) {
527 if (entry->offset != vma->node.start) { 547 if (entry->offset != vma->node.start) {
@@ -716,7 +736,7 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
716{ 736{
717 struct radix_tree_root *handles_vma = &eb->ctx->handles_vma; 737 struct radix_tree_root *handles_vma = &eb->ctx->handles_vma;
718 struct drm_i915_gem_object *obj; 738 struct drm_i915_gem_object *obj;
719 unsigned int i; 739 unsigned int i, batch;
720 int err; 740 int err;
721 741
722 if (unlikely(i915_gem_context_is_closed(eb->ctx))) 742 if (unlikely(i915_gem_context_is_closed(eb->ctx)))
@@ -728,6 +748,8 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
728 INIT_LIST_HEAD(&eb->relocs); 748 INIT_LIST_HEAD(&eb->relocs);
729 INIT_LIST_HEAD(&eb->unbound); 749 INIT_LIST_HEAD(&eb->unbound);
730 750
751 batch = eb_batch_index(eb);
752
731 for (i = 0; i < eb->buffer_count; i++) { 753 for (i = 0; i < eb->buffer_count; i++) {
732 u32 handle = eb->exec[i].handle; 754 u32 handle = eb->exec[i].handle;
733 struct i915_lut_handle *lut; 755 struct i915_lut_handle *lut;
@@ -770,33 +792,16 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
770 lut->handle = handle; 792 lut->handle = handle;
771 793
772add_vma: 794add_vma:
773 err = eb_add_vma(eb, i, vma); 795 err = eb_add_vma(eb, i, batch, vma);
774 if (unlikely(err)) 796 if (unlikely(err))
775 goto err_vma; 797 goto err_vma;
776 798
777 GEM_BUG_ON(vma != eb->vma[i]); 799 GEM_BUG_ON(vma != eb->vma[i]);
778 GEM_BUG_ON(vma->exec_flags != &eb->flags[i]); 800 GEM_BUG_ON(vma->exec_flags != &eb->flags[i]);
801 GEM_BUG_ON(drm_mm_node_allocated(&vma->node) &&
802 eb_vma_misplaced(&eb->exec[i], vma, eb->flags[i]));
779 } 803 }
780 804
781 /* take note of the batch buffer before we might reorder the lists */
782 i = eb_batch_index(eb);
783 eb->batch = eb->vma[i];
784 GEM_BUG_ON(eb->batch->exec_flags != &eb->flags[i]);
785
786 /*
787 * SNA is doing fancy tricks with compressing batch buffers, which leads
788 * to negative relocation deltas. Usually that works out ok since the
789 * relocate address is still positive, except when the batch is placed
790 * very low in the GTT. Ensure this doesn't happen.
791 *
792 * Note that actual hangs have only been observed on gen7, but for
793 * paranoia do it everywhere.
794 */
795 if (!(eb->flags[i] & EXEC_OBJECT_PINNED))
796 eb->flags[i] |= __EXEC_OBJECT_NEEDS_BIAS;
797 if (eb->reloc_cache.has_fence)
798 eb->flags[i] |= EXEC_OBJECT_NEEDS_FENCE;
799
800 eb->args->flags |= __EXEC_VALIDATED; 805 eb->args->flags |= __EXEC_VALIDATED;
801 return eb_reserve(eb); 806 return eb_reserve(eb);
802 807