All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH 04/17] drm/i915: Unify aliasing ppgtt handling
Date: Fri, 17 Apr 2015 16:36:02 +0300	[thread overview]
Message-ID: <87vbgu27y5.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <1429025727-15380-5-git-send-email-daniel.vetter@ffwll.ch>

Daniel Vetter <daniel.vetter@ffwll.ch> writes:

> With the dynamic pagetable alloc code aliasing ppgtt special-cases
> where again mixed in all over the place with the low-level init code.
>
> Extract the va preallocation and clearing again into the common code
> where aliasing ppgtt gets set up.
>
> Note that with this we don't set the size of the aliasing ppgtt to the
> size of the parent ggtt address space. Which isn't required at all
> since except for the ppgtt setup/cleanup code no one ever looks at
> this.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 134 +++++++-----------------------------
>  1 file changed, 24 insertions(+), 110 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index abb11f139d25..75787f1d2751 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -387,50 +387,6 @@ fail_bitmap:
>  	return ERR_PTR(ret);
>  }
>  
> -/**
> - * alloc_pt_range() - Allocate a multiple page tables
> - * @pd:		The page directory which will have at least @count entries
> - *		available to point to the allocated page tables.
> - * @pde:	First page directory entry for which we are allocating.
> - * @count:	Number of pages to allocate.
> - * @dev:	DRM device.
> - *
> - * Allocates multiple page table pages and sets the appropriate entries in the
> - * page table structure within the page directory. Function cleans up after
> - * itself on any failures.
> - *
> - * Return: 0 if allocation succeeded.
> - */
> -static int alloc_pt_range(struct i915_page_directory *pd, uint16_t pde, size_t count,
> -			  struct drm_device *dev)
> -{
> -	int i, ret;
> -
> -	/* 512 is the max page tables per page_directory on any platform. */
> -	if (WARN_ON(pde + count > I915_PDES))
> -		return -EINVAL;
> -
> -	for (i = pde; i < pde + count; i++) {
> -		struct i915_page_table *pt = alloc_pt_single(dev);
> -
> -		if (IS_ERR(pt)) {
> -			ret = PTR_ERR(pt);
> -			goto err_out;
> -		}
> -		WARN(pd->page_table[i],
> -		     "Leaking page directory entry %d (%p)\n",
> -		     i, pd->page_table[i]);
> -		pd->page_table[i] = pt;
> -	}
> -
> -	return 0;
> -
> -err_out:
> -	while (i-- > pde)
> -		unmap_and_free_pt(pd->page_table[i], dev);
> -	return ret;
> -}
> -
>  static void unmap_and_free_pd(struct i915_page_directory *pd,
>  			      struct drm_device *dev)
>  {
> @@ -971,7 +927,7 @@ err_out:
>   * space.
>   *
>   */
> -static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)
> +static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
>  {
>  	ppgtt->scratch_pt = alloc_pt_single(ppgtt->base.dev);
>  	if (IS_ERR(ppgtt->scratch_pt))
> @@ -985,8 +941,9 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)
>  	gen8_initialize_pd(&ppgtt->base, ppgtt->scratch_pd);
>  
>  	ppgtt->base.start = 0;
> -	ppgtt->base.total = size;
> +	ppgtt->base.total = 1ULL << 32;

This warns on 32bit builds due to overflow.

Seems that I have already tripped on this when I reviewed 4gb
default ppgtt size patch.

We should do a follow-up patch with:

--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -229,7 +229,7 @@ struct i915_address_space {
        struct drm_device *dev;
        struct list_head global_link;
        unsigned long start;            /* Start offset always 0 for
        dri2 */
-       size_t total;           /* size addr space maps (ex. 2GB for ggtt) */
+       u64 size;               /* size addr space maps (ex. 2GB for ggtt) */

-Mika


>  	ppgtt->base.cleanup = gen8_ppgtt_cleanup;
> +	ppgtt->base.allocate_va_range = gen8_alloc_va_range;
>  	ppgtt->base.insert_entries = gen8_ppgtt_insert_entries;
>  	ppgtt->base.clear_range = gen8_ppgtt_clear_range;
>  	ppgtt->base.unbind_vma = ppgtt_unbind_vma;
> @@ -997,46 +954,6 @@ static int gen8_ppgtt_init_common(struct i915_hw_ppgtt *ppgtt, uint64_t size)
>  	return 0;
>  }
>  
> -static int gen8_aliasing_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
> -{
> -	struct drm_device *dev = ppgtt->base.dev;
> -	struct drm_i915_private *dev_priv = dev->dev_private;
> -	uint64_t start = 0, size = dev_priv->gtt.base.total;
> -	int ret;
> -
> -	ret = gen8_ppgtt_init_common(ppgtt, dev_priv->gtt.base.total);
> -	if (ret)
> -		return ret;
> -
> -	/* Aliasing PPGTT has to always work and be mapped because of the way we
> -	 * use RESTORE_INHIBIT in the context switch. This will be fixed
> -	 * eventually. */
> -	ret = gen8_alloc_va_range(&ppgtt->base, start, size);
> -	if (ret) {
> -		unmap_and_free_pd(ppgtt->scratch_pd, ppgtt->base.dev);
> -		unmap_and_free_pt(ppgtt->scratch_pt, ppgtt->base.dev);
> -		return ret;
> -	}
> -
> -	ppgtt->base.allocate_va_range = NULL;
> -	ppgtt->base.clear_range(&ppgtt->base, 0, ppgtt->base.total, true);
> -
> -	return 0;
> -}
> -
> -static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
> -{
> -	int ret;
> -
> -	ret = gen8_ppgtt_init_common(ppgtt, (1ULL << 32));
> -	if (ret)
> -		return ret;
> -
> -	ppgtt->base.allocate_va_range = gen8_alloc_va_range;
> -
> -	return 0;
> -}
> -
>  static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
>  {
>  	struct i915_address_space *vm = &ppgtt->base;
> @@ -1533,7 +1450,7 @@ static void gen6_scratch_va_range(struct i915_hw_ppgtt *ppgtt,
>  		ppgtt->pd.page_table[pde] = ppgtt->scratch_pt;
>  }
>  
> -static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing)
> +static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
>  {
>  	struct drm_device *dev = ppgtt->base.dev;
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> @@ -1556,18 +1473,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing)
>  	if (ret)
>  		return ret;
>  
> -	if (aliasing) {
> -		/* preallocate all pts */
> -		ret = alloc_pt_range(&ppgtt->pd, 0, I915_PDES,
> -				ppgtt->base.dev);
> -
> -		if (ret) {
> -			gen6_ppgtt_cleanup(&ppgtt->base);
> -			return ret;
> -		}
> -	}
> -
> -	ppgtt->base.allocate_va_range = aliasing ? NULL : gen6_alloc_va_range;
> +	ppgtt->base.allocate_va_range = gen6_alloc_va_range;
>  	ppgtt->base.clear_range = gen6_ppgtt_clear_range;
>  	ppgtt->base.insert_entries = gen6_ppgtt_insert_entries;
>  	ppgtt->base.unbind_vma = ppgtt_unbind_vma;
> @@ -1583,10 +1489,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing)
>  	ppgtt->pd_addr = (gen6_pte_t __iomem *)dev_priv->gtt.gsm +
>  		ppgtt->pd.pd_offset / sizeof(gen6_pte_t);
>  
> -	if (aliasing)
> -		ppgtt->base.clear_range(&ppgtt->base, 0, ppgtt->base.total, true);
> -	else
> -		gen6_scratch_va_range(ppgtt, 0, ppgtt->base.total);
> +	gen6_scratch_va_range(ppgtt, 0, ppgtt->base.total);
>  
>  	gen6_write_page_range(dev_priv, &ppgtt->pd, 0, ppgtt->base.total);
>  
> @@ -1600,8 +1503,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt, bool aliasing)
>  	return 0;
>  }
>  
> -static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt,
> -		bool aliasing)
> +static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  
> @@ -1609,9 +1511,7 @@ static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt,
>  	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
>  
>  	if (INTEL_INFO(dev)->gen < 8)
> -		return gen6_ppgtt_init(ppgtt, aliasing);
> -	else if (aliasing)
> -		return gen8_aliasing_ppgtt_init(ppgtt);
> +		return gen6_ppgtt_init(ppgtt);
>  	else
>  		return gen8_ppgtt_init(ppgtt);
>  }
> @@ -1620,7 +1520,7 @@ int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	int ret = 0;
>  
> -	ret = __hw_ppgtt_init(dev, ppgtt, false);
> +	ret = __hw_ppgtt_init(dev, ppgtt);
>  	if (ret == 0) {
>  		kref_init(&ppgtt->ref);
>  		drm_mm_init(&ppgtt->base.mm, ppgtt->base.start,
> @@ -2255,13 +2155,27 @@ static int i915_gem_setup_global_gtt(struct drm_device *dev,
>  		if (!ppgtt)
>  			return -ENOMEM;
>  
> -		ret = __hw_ppgtt_init(dev, ppgtt, true);
> +		ret = __hw_ppgtt_init(dev, ppgtt);
> +		if (ret) {
> +			ppgtt->base.cleanup(&ppgtt->base);
> +			kfree(ppgtt);
> +			return ret;
> +		}
> +
> +		if (ppgtt->base.allocate_va_range)
> +			ret = ppgtt->base.allocate_va_range(&ppgtt->base, 0,
> +							    ppgtt->base.total);
>  		if (ret) {
>  			ppgtt->base.cleanup(&ppgtt->base);
>  			kfree(ppgtt);
>  			return ret;
>  		}
>  
> +		ppgtt->base.clear_range(&ppgtt->base,
> +					ppgtt->base.start,
> +					ppgtt->base.total,
> +					true);
> +
>  		dev_priv->mm.aliasing_ppgtt = ppgtt;
>  	}
>  
> -- 
> 2.1.0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-04-17 13:36 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 15:35 [PATCH 00/17] i915_gem_gtt.c polish Daniel Vetter
2015-04-14 15:35 ` [PATCH 01/17] drm/i915: Move gen8 clear_range vfunc setup into common code Daniel Vetter
2015-04-17 14:11   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 02/17] drm/i915: Move vma vfuns to adddress_space Daniel Vetter
2015-04-14 16:09   ` Chris Wilson
2015-04-14 16:12     ` Chris Wilson
2015-04-14 17:08       ` Daniel Vetter
2015-04-14 17:23         ` Chris Wilson
2015-04-16  6:18     ` Mika Kuoppala
2015-04-16  7:39       ` Chris Wilson
2015-04-17 14:15   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 03/17] drm/i915: Clean up aliasing ppgtt correctly on error paths Daniel Vetter
2015-04-17 14:34   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 04/17] drm/i915: Unify aliasing ppgtt handling Daniel Vetter
2015-04-17 13:36   ` Mika Kuoppala [this message]
2015-04-17 16:21   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 05/17] drm/i915: Move PTE_READ_ONLY to ->pte_encode vfunc Daniel Vetter
2015-04-17 16:22   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 06/17] drm/i915: Dont clear PIN_GLOBAL in the execbuf pinning fallback Daniel Vetter
2015-04-14 15:53   ` Chris Wilson
2015-04-14 16:33     ` Chris Wilson
2015-04-14 17:01   ` [PATCH] " Daniel Vetter
2015-04-15 21:50     ` shuang.he
2015-04-14 15:35 ` [PATCH 07/17] drm/i915: Drop redundant GGTT rebinding Daniel Vetter
2015-04-14 16:03   ` Chris Wilson
2015-04-14 15:35 ` [PATCH 08/17] drm/i915: Don't look at pg_dirty_rings for aliasing ppgtt Daniel Vetter
2015-04-14 16:06   ` Chris Wilson
2015-04-14 17:11     ` Daniel Vetter
2015-04-14 17:53       ` Chris Wilson
2015-04-15 10:44         ` Daniel Vetter
2015-04-17 13:49           ` Mika Kuoppala
2015-04-20 16:02             ` Daniel Vetter
2015-04-20 16:08             ` Daniel Vetter
2015-04-21  8:18               ` Mika Kuoppala
2015-04-23 15:43             ` Chris Wilson
2015-04-23 18:56               ` Daniel Vetter
2015-04-23 19:52                 ` Chris Wilson
2015-04-23 21:52                 ` Chris Wilson
2015-07-31 16:26                 ` Chris Wilson
2015-07-31 17:38                   ` Chris Wilson
2015-04-14 15:35 ` [PATCH 09/17] drm/i915: Don't use atomics for pg_dirty_rings Daniel Vetter
2015-04-17 16:39   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 10/17] drm/i915: Remove misleading comment around bind_to_vm Daniel Vetter
2015-04-17 18:09   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 11/17] drm/i915: Fix up the vma aliasing ppgtt binding Daniel Vetter
2015-04-15 10:47   ` Chris Wilson
2015-04-16  8:01     ` Daniel Vetter
2015-04-16  8:07       ` Chris Wilson
2015-04-16  8:57         ` Daniel Vetter
2015-04-20 16:04   ` [PATCH] " Daniel Vetter
2015-04-21 13:29     ` Mika Kuoppala
2015-04-24 11:14     ` Chris Wilson
2015-04-24 11:55       ` Chris Wilson
2015-05-04  8:49         ` Daniel Vetter
2015-05-04  9:06           ` Chris Wilson
2015-05-04  9:20             ` Daniel Vetter
2015-04-14 15:35 ` [PATCH 12/17] drm/i915: Arm cmd parser with aliasng ppgtt only Daniel Vetter
2015-04-14 18:10   ` Chris Wilson
2015-04-15  9:43     ` Daniel Vetter
2015-04-15 10:07       ` Chris Wilson
2015-04-15 10:28         ` Daniel Vetter
2015-04-30 10:37           ` Jani Nikula
2015-04-24 12:57   ` Mika Kuoppala
2015-05-04  8:54     ` [PATCH] drm/i915: Simplify cmd-parser DISPATCH_SECURE check Daniel Vetter
2015-05-04  9:23       ` Daniel Vetter
2015-05-04 12:52       ` shuang.he
2015-04-14 15:35 ` [PATCH 13/17] drm/i915: move i915_gem_restore_gtt_mappings around Daniel Vetter
2015-04-14 15:35 ` [PATCH 14/17] drm/i915: Move ppgtt_bind/unbind around Daniel Vetter
2015-04-14 15:35 ` [PATCH 15/17] drm/i915: Unduplicate i915_ggtt_unbind/bind_vma Daniel Vetter
2015-04-14 15:35 ` [PATCH 16/17] drm/i915: Don't try to outsmart gcc in i915_gem_gtt.c Daniel Vetter
2015-04-14 15:35 ` [PATCH 17/17] drm/i915: Move i915_get_ggtt_vma_pages into ggtt_bind_vma Daniel Vetter
2015-04-21 13:36   ` Mika Kuoppala
2015-04-23 19:08     ` Daniel Vetter
2015-04-15 10:49 ` [PATCH 00/17] i915_gem_gtt.c polish Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vbgu27y5.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.