[Intel-gfx] [PATCH] drm/i915: Avoid writing relocs with addresses in non-canonical form

Chris Wilson chris at chris-wilson.co.uk
Fri Dec 4 04:05:09 PST 2015


On Fri, Dec 04, 2015 at 12:33:44PM +0100, Michał Winiarski wrote:
> According to bspec, some parts of HW expect the addresses to be in
> a canonical form, where bits [63:48] == [47]. Let's convert addresses to
> canonical form prior to relocating and return converted offsets to
> userspace.
> 
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: Michel Thierry <michel.thierry at intel.com>
> Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 9 ++++++---
>  drivers/gpu/drm/i915/i915_gem_gtt.h        | 5 +++++
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> index a4c243c..9f27be9 100644
> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> @@ -395,7 +395,7 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
>  	target_i915_obj = target_vma->obj;
>  	target_obj = &target_vma->obj->base;
>  
> -	target_offset = target_vma->node.start;
> +	target_offset = gen8_canonical_addr(target_vma->node.start);

Ok, this keeps userspace in sync as well as writing the cannonical
addreses to hardware.

>  	/* Sandybridge PPGTT errata: We need a global gtt mapping for MI and
>  	 * pipe_control writes because the gpu doesn't properly redirect them
> @@ -583,6 +583,7 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
>  	struct drm_i915_gem_object *obj = vma->obj;
>  	struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
>  	uint64_t flags;
> +	uint64_t offset;
>  	int ret;
>  
>  	flags = PIN_USER;
> @@ -623,8 +624,10 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
>  			entry->flags |= __EXEC_OBJECT_HAS_FENCE;
>  	}
>  
> -	if (entry->offset != vma->node.start) {
> -		entry->offset = vma->node.start;
> +	offset = gen8_canonical_addr(vma->node.start);
> +

Kill the extra line.

> +	if (entry->offset != offset) {
> +		entry->offset = offset;
>  		*need_reloc = true;

And this copies back the cannonical address to userspace. Ok, the
userspace side looks correct (the presumed_offset and execobject.offsets
will be updated to store the cannonical address).

>  	}
>  
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
> index 877c32c..65e8f88 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.h
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
> @@ -507,6 +507,11 @@ static inline size_t gen8_pte_count(uint64_t address, uint64_t length)
>  	return i915_pte_count(address, length, GEN8_PDE_SHIFT);
>  }
>  
> +static inline uint64_t gen8_canonical_addr(uint64_t address)
> +{

You need the bspec reference here as well.

Looks good to me, with just a quick explanation here as to what we are
doing and why.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the Intel-gfx mailing list