Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Detect invalid pages for SandyBridge
Date: Thu, 27 Sep 2012 14:14:22 +0200	[thread overview]
Message-ID: <20120927121422.GC2098@bremse> (raw)
In-Reply-To: <1348734477-23369-1-git-send-email-chris@chris-wilson.co.uk>

On Thu, Sep 27, 2012 at 09:27:57AM +0100, Chris Wilson wrote:
> As SandyBridge returns garbage when decoding certain addresses through
> the GTT (all memory below 1MiB and a very small number of individual
> pages) we need to prevent the GPU from utilizing those pages. The
> ultimate goal would be to prevent our allocator from handing us those
> pages, but that is a longer term project. In the short term, we can
> detect when we attempt to bind those pages to the GPU and return an
> error to the application rather than hang the GPU and potentially the
> system.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c |   40 ++++++++++++++++++++++++++++++++---
>  1 file changed, 37 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index d9d3fc7..5c7ccfd 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -306,17 +306,51 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
>  	intel_gtt_chipset_flush();
>  }
>  
> +static bool
> +gen6_valid_addresses(struct drm_i915_gem_object *obj)
> +{
> +	struct scatterlist *sg;
> +	int i;
> +
> +	for_each_sg(obj->pages->sgl, sg, obj->pages->nents, i) {
> +		dma_addr_t addr = sg_dma_address(sg);
> +		if (WARN(addr < 0x100000 ||
> +			 addr == 0x20050000 ||
> +			 addr == 0x20110000 ||
> +			 addr == 0x20130000 ||
> +			 addr == 0x20138000 ||
> +			 addr == 0x40004000,
> +			 "object references unaddressable physical pages: addr=%x",
> +			 (u32)addr))
> +			return false;

Iirc the bug is about the physical address, no the remapped one after
dmar. We'd need to check the windows code for that though ...
-Daniel

> +	}
> +
> +	return true;
> +}
> +
>  int i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj)
>  {
> -	if (obj->has_dma_mapping)
> -		return 0;
> +	int ret;
>  
> -	if (!dma_map_sg(&obj->base.dev->pdev->dev,
> +	if (!obj->has_dma_mapping &&
> +	    !dma_map_sg(&obj->base.dev->pdev->dev,
>  			obj->pages->sgl, obj->pages->nents,
>  			PCI_DMA_BIDIRECTIONAL))
>  		return -ENOSPC;
>  
> +	if (IS_GEN6(obj->base.dev) && !gen6_valid_addresses(obj)) {
> +		ret = -EFAULT;
> +		goto unmap;
> +	}
> +
>  	return 0;
> +
> +unmap:
> +	if (!obj->has_dma_mapping)
> +		dma_unmap_sg(&obj->base.dev->pdev->dev,
> +			     obj->pages->sgl, obj->pages->nents,
> +			     PCI_DMA_BIDIRECTIONAL);
> +	return ret;
>  }
>  
>  void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

  reply	other threads:[~2012-09-27 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-27  8:27 [PATCH] drm/i915: Detect invalid pages for SandyBridge Chris Wilson
2012-09-27 12:14 ` Daniel Vetter [this message]
2012-09-27 12:16   ` Daniel Vetter
2012-09-27 12:22     ` 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=20120927121422.GC2098@bremse \
    --to=daniel@ffwll.ch \
    --cc=chris@chris-wilson.co.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox