All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org, Paulo Zanoni <paulo.r.zanoni@intel.com>
Subject: Re: [PATCH 2/2] drm/i915: Check that the DMA address for stolen fits within dma_addr_t
Date: Fri, 27 Jan 2017 19:05:57 +0200	[thread overview]
Message-ID: <20170127170557.GI31595@intel.com> (raw)
In-Reply-To: <20170127165531.28135-2-chris@chris-wilson.co.uk>

On Fri, Jan 27, 2017 at 04:55:31PM +0000, Chris Wilson wrote:
> Just sanity check that the value we deduce from the stolen memory
> register fits within the kernel's dma_addr_t and doesn't overflow.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem_stolen.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
> index 42bbc4b04fd6..4f1f3090c0ed 100644
> --- a/drivers/gpu/drm/i915/i915_gem_stolen.c
> +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
> @@ -211,6 +211,14 @@ static dma_addr_t i915_stolen_to_dma(struct drm_i915_private *dev_priv)
>  			ggtt_start &= PGTBL_ADDRESS_LO_MASK;
>  		ggtt_end = ggtt_start + ggtt_total_entries(ggtt) * 4;
>  
> +		if (ggtt_end <= ggtt_start ||
> +		    overflows_type(ggtt_end, dma_addr_t)) {
> +			DRM_ERROR("DMA address for reserved igfx memory [%llx - %llx] does not fit within the kernel's %db dma_addr_t\n",
> +				  ggtt_start, ggtt_end,
> +				  (int)sizeof(dma_addr_t) * 8);
> +			return 0;
> +		}

This would only check if the ggtt location fits into dma_addr_t.
We don't need that since we never touch the ggtt directly with
either the CPU or GPU. So I think this piece of code should keep
on using u64 as it needs to be able to hold the 36 address we read
from the hardware/firmware.

> +
>  		if (ggtt_start >= stolen[0].start && ggtt_start < stolen[0].end)
>  			stolen[0].end = ggtt_start;
>  		if (ggtt_end > stolen[1].start && ggtt_end <= stolen[1].end)
> -- 
> 2.11.0

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-01-27 17:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-27 16:55 [PATCH 1/2] drm/i915: Treat stolen memory as DMA addresses Chris Wilson
2017-01-27 16:55 ` [PATCH 2/2] drm/i915: Check that the DMA address for stolen fits within dma_addr_t Chris Wilson
2017-01-27 17:05   ` Ville Syrjälä [this message]
2017-01-27 17:18     ` Chris Wilson
2017-01-27 17:20   ` [PATCH] drm/i915: Sanity check the computed size and base of stolen memory Chris Wilson
2017-01-27 20:57     ` Paulo Zanoni
2017-01-30 12:41     ` Joonas Lahtinen
2017-01-30 13:15       ` Chris Wilson
2017-01-30 13:45         ` Joonas Lahtinen
2017-01-30 13:47       ` [PATCH v2] " Chris Wilson
2017-01-31 10:13         ` Joonas Lahtinen
2017-01-31 16:08           ` Chris Wilson
2017-01-27 20:50 ` [PATCH 1/2] drm/i915: Treat stolen memory as DMA addresses Paulo Zanoni
2017-01-27 21:12   ` Chris Wilson
2017-01-30 21:24 ` ✗ Fi.CI.BAT: warning for series starting with [1/2] drm/i915: Treat stolen memory as DMA addresses (rev4) Patchwork

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=20170127170557.GI31595@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=paulo.r.zanoni@intel.com \
    /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.