[Intel-gfx] [PATCH v2 3/3] drm/i915: Use page coloring to provide the guard page at the end of the GTT
Matthew Auld
matthew.william.auld at gmail.com
Mon Feb 6 12:54:39 UTC 2017
On 6 February 2017 at 08:45, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> As we now mark the reserved hole (drm_mm.head_node) with the special
> UNEVICTABLE color, we can use the page coloring to avoid prefetching of
> the CS beyond the end of the GTT.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> drivers/gpu/drm/i915/i915_gem_evict.c | 10 ++++++++--
> drivers/gpu/drm/i915/i915_gem_gtt.c | 19 ++++++++++++-------
> 2 files changed, 20 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
> index c181b1bb3d2c..776c508cb9ae 100644
> --- a/drivers/gpu/drm/i915/i915_gem_evict.c
> +++ b/drivers/gpu/drm/i915/i915_gem_evict.c
> @@ -258,6 +258,9 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
> int ret = 0;
>
> lockdep_assert_held(&vm->i915->drm.struct_mutex);
> + GEM_BUG_ON(!IS_ALIGNED(start, I915_GTT_PAGE_SIZE));
> + GEM_BUG_ON(!IS_ALIGNED(end, I915_GTT_PAGE_SIZE));
> +
> trace_i915_gem_evict_node(vm, target, flags);
>
> /* Retire before we search the active list. Although we have
> @@ -273,9 +276,11 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
> /* Expand search to cover neighbouring guard pages (or lack!) */
> if (start > vm->start)
> start -= I915_GTT_PAGE_SIZE;
> - if (end < vm->start + vm->total)
> - end += I915_GTT_PAGE_SIZE;
> +
> + /* Always look at the page afterwards to avoid the end-of-GTT */
> + end += I915_GTT_PAGE_SIZE;
> }
> + GEM_BUG_ON(start >= end);
>
> drm_mm_for_each_node_in_range(node, &vm->mm, start, end) {
> /* If we find any non-objects (!vma), we cannot evict them */
> @@ -284,6 +289,7 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
> break;
> }
>
> + GEM_BUG_ON(!node->allocated);
> vma = container_of(node, typeof(*vma), node);
>
> /* If we are using coloring to insert guard pages between
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 75cd2a56b8b4..959764394718 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -2718,11 +2718,16 @@ static void i915_gtt_color_adjust(const struct drm_mm_node *node,
> u64 *start,
> u64 *end)
> {
> - if (node->color != color)
> + if (node->allocated && node->color != color)
> *start += I915_GTT_PAGE_SIZE;
>
> + /* Also leave a space between the unallocated reserved node after the
> + * GTT and any objects within the GTT, i.e. we use the color adjustment
> + * to insert a guard page to prevent prefetches crossing over the
> + * GTT boundary.
> + */
> node = list_next_entry(node, node_list);
> - if (node->allocated && node->color != color)
> + if (node->color != color)
> *end -= I915_GTT_PAGE_SIZE;
> }
>
> @@ -3241,14 +3246,14 @@ int i915_ggtt_init_hw(struct drm_i915_private *dev_priv)
>
> INIT_LIST_HEAD(&dev_priv->vm_list);
>
> - /* Subtract the guard page before address space initialization to
> - * shrink the range used by drm_mm.
> + /* Note that we use page colouring to enforce a guard page at the
> + * end of the address space. This is required as the CS may prefetch
> + * beyond the end of the batch buffer, across the page boundary,
> + * and beyond the end of the GTT if we do provide a guard.
if we do not provide a guard?
Reviewed-by: Matthew Auld <matthew.auld at intel.com>
More information about the Intel-gfx
mailing list