From mboxrd@z Thu Jan 1 00:00:00 1970 From: Damien Lespiau Subject: Re: [PATCH 03/17] drm/i915: Pin pages whilst mapping the dma-buf Date: Fri, 30 Aug 2013 15:27:47 +0100 Message-ID: <20130830142747.GD30430@strange.amr.corp.intel.com> References: <1377557469-4078-1-git-send-email-rodrigo.vivi@gmail.com> <1377557469-4078-4-git-send-email-rodrigo.vivi@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A1AFE7F3B for ; Fri, 30 Aug 2013 07:28:14 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1377557469-4078-4-git-send-email-rodrigo.vivi@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Rodrigo Vivi Cc: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Mon, Aug 26, 2013 at 07:50:55PM -0300, Rodrigo Vivi wrote: > From: Chris Wilson > > 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 Reviewed-by: Damien Lespiau -- 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