public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Damien Lespiau <damien.lespiau@intel.com>
To: Rodrigo Vivi <rodrigo.vivi@gmail.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 03/17] drm/i915: Pin pages whilst mapping the dma-buf
Date: Fri, 30 Aug 2013 15:27:47 +0100	[thread overview]
Message-ID: <20130830142747.GD30430@strange.amr.corp.intel.com> (raw)
In-Reply-To: <1377557469-4078-4-git-send-email-rodrigo.vivi@gmail.com>

On Mon, Aug 26, 2013 at 07:50:55PM -0300, Rodrigo Vivi wrote:
> From: Chris Wilson <chris@chris-wilson.co.uk>
> 
> As we attempt to kmalloc after calling get_pages, there is a possibility
> that the shrinker may reap the pages we just acquired. To prevent this
> we need to increment the pages_pin_count early, so rearrange the code
> and error paths to make it so.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>

-- 
Damien

> ---
>  drivers/gpu/drm/i915/i915_gem_dmabuf.c | 41 ++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> index e918b05..7d5752f 100644
> --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
> @@ -42,27 +42,24 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
>  
>  	ret = i915_mutex_lock_interruptible(obj->base.dev);
>  	if (ret)
> -		return ERR_PTR(ret);
> +		goto err;
>  
>  	ret = i915_gem_object_get_pages(obj);
> -	if (ret) {
> -		st = ERR_PTR(ret);
> -		goto out;
> -	}
> +	if (ret)
> +		goto err_unlock;
> +
> +	i915_gem_object_pin_pages(obj);
>  
>  	/* Copy sg so that we make an independent mapping */
>  	st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
>  	if (st == NULL) {
> -		st = ERR_PTR(-ENOMEM);
> -		goto out;
> +		ret = -ENOMEM;
> +		goto err_unpin;
>  	}
>  
>  	ret = sg_alloc_table(st, obj->pages->nents, GFP_KERNEL);
> -	if (ret) {
> -		kfree(st);
> -		st = ERR_PTR(ret);
> -		goto out;
> -	}
> +	if (ret)
> +		goto err_free;
>  
>  	src = obj->pages->sgl;
>  	dst = st->sgl;
> @@ -73,17 +70,23 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
>  	}
>  
>  	if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) {
> -		sg_free_table(st);
> -		kfree(st);
> -		st = ERR_PTR(-ENOMEM);
> -		goto out;
> +		ret =-ENOMEM;
> +		goto err_free_sg;
>  	}
>  
> -	i915_gem_object_pin_pages(obj);
> -
> -out:
>  	mutex_unlock(&obj->base.dev->struct_mutex);
>  	return st;
> +
> +err_free_sg:
> +	sg_free_table(st);
> +err_free:
> +	kfree(st);
> +err_unpin:
> +	i915_gem_object_unpin_pages(obj);
> +err_unlock:
> +	mutex_unlock(&obj->base.dev->struct_mutex);
> +err:
> +	return ERR_PTR(ret);
>  }
>  
>  static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
> -- 
> 1.8.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2013-08-30 14:28 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-26 22:50 [PATCH 00/17] drm-intel-collector WW34 - Simple patches as series for review Rodrigo Vivi
2013-08-26 22:50 ` [PATCH 01/17] drm/i915: Do not add an interrupt for a context switch Rodrigo Vivi
2013-08-30 14:17   ` Damien Lespiau
2013-08-26 22:50 ` [PATCH 02/17] drm/i915: Rearrange the comments in i915_add_request() Rodrigo Vivi
2013-08-30 14:21   ` Damien Lespiau
2013-08-26 22:50 ` [PATCH 03/17] drm/i915: Pin pages whilst mapping the dma-buf Rodrigo Vivi
2013-08-30 14:27   ` Damien Lespiau [this message]
2013-09-02  6:04     ` Daniel Vetter
2013-08-26 22:50 ` [PATCH 04/17] drm/i915: check that the i965g/gm 4G limit is really obeyed Rodrigo Vivi
2013-08-26 22:50 ` [PATCH 05/17] drm/i915: Cancel outstanding modeset workers before suspend Rodrigo Vivi
2013-08-26 22:50 ` [PATCH 06/17] drm/i915: split PCI IDs out into i915_drm.h v4 Rodrigo Vivi
2013-08-29 17:27   ` Ben Widawsky
2013-08-26 22:50 ` [PATCH 07/17] x86: add early quirk for reserving Intel graphics stolen memory v5 Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 08/17] drm/i915: Always prefer CPU relocations with LLC Rodrigo Vivi
2013-08-27 14:49   ` Ville Syrjälä
2013-08-27 15:25     ` Daniel Vetter
2013-08-29 17:20   ` Ben Widawsky
2013-08-29 19:11     ` Daniel Vetter
2013-08-29 19:16       ` Ben Widawsky
2013-08-26 22:51 ` [PATCH 09/17] drm/i915: Report requested frequency alongside current frequency in debugfs Rodrigo Vivi
2013-08-27 12:12   ` Rodrigo Vivi
2013-08-27 12:36     ` Chris Wilson
2013-08-28  8:15     ` Daniel Vetter
2013-08-26 22:51 ` [PATCH 10/17] drm/i915: Move the conditional seqno query into the tracepoint Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 11/17] drm/i915: Add some missing steps to i915_driver_load error path Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 12/17] drm/i915: Asynchronously perform the set-base for a simple modeset Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 13/17] drm/i915: Align tiled scanouts from stolen memory to 256k in the GTT Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 14/17] drm/i915: Apply the force-detect VGA w/a to Valleyview Rodrigo Vivi
2013-08-27  9:27   ` Daniel Vetter
2013-08-26 22:51 ` [PATCH 15/17] drm/i915: Pair seqno completion tracepoint with its dispatch Rodrigo Vivi
2013-08-26 22:51 ` [PATCH 16/17] RFM drm/i915: Boost RPS frequency for CPU stalls Rodrigo Vivi
2013-08-26 22:56   ` Chris Wilson
2013-08-26 22:51 ` [PATCH 17/17] drm/i915: Enable Lower Slice on Haswell GT3 Rodrigo Vivi
2013-08-27 15:31   ` Rodrigo Vivi
2013-08-27 17:05     ` Rodrigo Vivi
2013-08-27  9:39 ` [PATCH 00/17] drm-intel-collector WW34 - Simple patches as series for review Daniel Vetter
2013-08-27 10:23   ` Chris Wilson
2013-08-27 12:48   ` Rodrigo Vivi
2013-08-27 16:19   ` Chris Wilson
2013-08-27 17:04     ` Rodrigo Vivi

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=20130830142747.GD30430@strange.amr.corp.intel.com \
    --to=damien.lespiau@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=rodrigo.vivi@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox