Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp503771yba; Fri, 12 Apr 2019 07:53:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbOp9moGNIoNe0cWTD30+va1Cg4CZ2VzUc7v85t237x0mFe8chONQ6oo/tIw5S5TNLMj2T X-Received: by 2002:aa7:91c8:: with SMTP id z8mr57431636pfa.110.1555080837370; Fri, 12 Apr 2019 07:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555080837; cv=none; d=google.com; s=arc-20160816; b=zqKBUmI8ksSTTyekkrtoqB/sxM+BpX4/aay6OxBeEkb+bn21kwxCTZ4b1gb41yHVBw 2OShPfZL39GAEils4iBSBwD0mfJClmVoaUpFF97myeyViqTbMeQEbcUEtS8r6Q4gEBXU pKkx3h5EF0PVp+Y/Cf19w66u+568kkLnWGmY3CqPPVIQdgCMQ/kVF/UF6TbJCcKboetq 9JbhOIg1jCiue/3xbLmD4NYRPKJMyR7Cb2T3mJIEGfiRI8+oeHCKpVttoc2OZDmltvYR S//ak2Q0Tqh8EUmr3FQj1UZIWRUeL1//QG2YniN8UVCFZVL1tjLPdsSTcU/YMkUkjp7S Pewg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=bKKTWdo63weVkoc/E3/wKZUmkzk9PduzeoVonxM7Nno=; b=Uh6vTIQ1PM+XpKB88Ckqj1eSScEwAdEkLgrpNBayUPRf9YRb3D50dc9i9HcAcPQjNB 7/evvA1epTNcAbaIjeiu0D3FR+PMU/wQJHlyorzzfrf4rktLogYSRaQyx//0xOsUlz6W /4+fRxCuf1bzEDSipr5r5Lf4uXryHwZ4uMMVS0UzJE0ZBCpJ6RZ/AxVbXOqNiW02Dz2i rih5bDxAR/O/ENOcPWHq7p8TC2DBlXCfMk6PyEyd/3uqv2ywPubrHMr1zRXS11qVzNBE zwghicywzq9+Q18lV4iUX+euGzuhluQKPGV9DKDXhRMEdVRMAs19XJwG0PeVGTA7RJKR sm8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w25si37723966pgl.346.2019.04.12.07.53.37; Fri, 12 Apr 2019 07:53:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbfDLOw2 (ORCPT + 99 others); Fri, 12 Apr 2019 10:52:28 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:51632 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfDLOw2 (ORCPT ); Fri, 12 Apr 2019 10:52:28 -0400 Received: by mail-it1-f196.google.com with SMTP id s3so1397972itk.1 for ; Fri, 12 Apr 2019 07:52:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bKKTWdo63weVkoc/E3/wKZUmkzk9PduzeoVonxM7Nno=; b=JRPVL+KLCtMTMEl7aQNUyZnZ4pXOYNW8hzQlUoEBAcGGXn7V7jO6c3M5bgqLCBDQfu yOlqfp8xyU808ro8PfcJH4XX5bDE7iH5C4BMWnqhqflRg2fGZhJieTGxygO1XtzO5h54 NwdSDC0M/Ga2P4sa4pkEKrmZdYLf1UO1kLe2thLtrqJRjme92AwDpR1h7zdn+nri5woi onWzyMZB9s2ujF01e+q6yDwVX4fLbgxmUX3N3AYzeIbbsLEnpBPkRmDxPbCSNmLXb9+n ZaFwTPBzvfsvKRZA8OKPaK622QnlcJYijwCYHvgOZrB5tXJLF1Rpfha6GNclUOc9+S92 7q8w== X-Gm-Message-State: APjAAAWKMz43PLavDd0odElCL8kv0/vqM6URTKE1VnrZZJTdsX3nc/pX kqjgr/iIJMkflJsQ2vm1XFSNVsPzQPVZtbGm//I= X-Received: by 2002:a24:6583:: with SMTP id u125mr11854013itb.151.1555080746701; Fri, 12 Apr 2019 07:52:26 -0700 (PDT) MIME-Version: 1.0 References: <20190409205427.6943-1-robh@kernel.org> <20190409205427.6943-3-robh@kernel.org> In-Reply-To: <20190409205427.6943-3-robh@kernel.org> From: Tomeu Vizoso Date: Fri, 12 Apr 2019 16:52:15 +0200 Message-ID: Subject: Re: [PATCH v3 2/3] drm: Add a drm_gem_objects_lookup helper To: Rob Herring Cc: dri-devel , Maxime Ripard , open list , David Airlie , Sean Paul , Alyssa Rosenzweig Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Acked-by: Tomeu Vizoso On Tue, 9 Apr 2019 at 22:54, Rob Herring wrote: > > Similar to the single handle drm_gem_object_lookup(), > drm_gem_objects_lookup() takes an array of handles and returns an array > of GEM objects. > > v2: > - Take the userspace pointer directly and allocate the array. > - Expand the function documentation. > > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Sean Paul > Cc: David Airlie > Cc: Daniel Vetter > Acked-by: Alyssa Rosenzweig > Signed-off-by: Rob Herring > --- > drivers/gpu/drm/drm_gem.c | 93 ++++++++++++++++++++++++++++++++++----- > include/drm/drm_gem.h | 2 + > 2 files changed, 85 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 388b3742e562..faa2718e85e8 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -663,6 +663,85 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, > } > EXPORT_SYMBOL(drm_gem_put_pages); > > +static int objects_lookup(struct drm_file *filp, u32 *handle, int count, > + struct drm_gem_object **objs) > +{ > + int i, ret = 0; > + struct drm_gem_object *obj; > + > + spin_lock(&filp->table_lock); > + > + for (i = 0; i < count; i++) { > + /* Check if we currently have a reference on the object */ > + obj = idr_find(&filp->object_idr, handle[i]); > + if (!obj) { > + ret = -ENOENT; > + break; > + } > + drm_gem_object_get(obj); > + objs[i] = obj; > + } > + spin_unlock(&filp->table_lock); > + > + return ret; > +} > + > +/** > + * drm_gem_objects_lookup - look up GEM objects from an array of handles > + * @filp: DRM file private date > + * @bo_handles: user pointer to array of userspace handle > + * @count: size of handle array > + * @objs_out: returned pointer to array of drm_gem_object pointers > + * > + * Takes an array of userspace handles and returns a newly allocated array of > + * GEM objects. > + * > + * For a single handle lookup, use drm_gem_object_lookup(). > + * > + * Returns: > + * > + * @objs filled in with GEM object pointers. Returned GEM objects need to be > + * released with drm_gem_object_put(). -ENOENT is returned on a lookup > + * failure. 0 is returned on success. > + * > + */ > +int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, > + int count, struct drm_gem_object ***objs_out) > +{ > + int ret; > + u32 *handles; > + struct drm_gem_object **objs; > + > + if (!count) > + return 0; > + > + objs = kvmalloc_array(count, sizeof(struct drm_gem_object *), > + GFP_KERNEL | __GFP_ZERO); > + if (!objs) > + return -ENOMEM; > + > + handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL); > + if (!handles) { > + ret = -ENOMEM; > + goto out; > + } > + > + if (copy_from_user(handles, bo_handles, count * sizeof(u32))) { > + ret = -EFAULT; > + DRM_DEBUG("Failed to copy in GEM handles\n"); > + goto out; > + } > + > + ret = objects_lookup(filp, handles, count, objs); > + *objs_out = objs; > + > +out: > + kvfree(handles); > + return ret; > + > +} > +EXPORT_SYMBOL(drm_gem_objects_lookup); > + > /** > * drm_gem_object_lookup - look up a GEM object from its handle > * @filp: DRM file private date > @@ -672,21 +751,15 @@ EXPORT_SYMBOL(drm_gem_put_pages); > * > * A reference to the object named by the handle if such exists on @filp, NULL > * otherwise. > + * > + * If looking up an array of handles, use drm_gem_objects_lookup(). > */ > struct drm_gem_object * > drm_gem_object_lookup(struct drm_file *filp, u32 handle) > { > - struct drm_gem_object *obj; > - > - spin_lock(&filp->table_lock); > - > - /* Check if we currently have a reference on the object */ > - obj = idr_find(&filp->object_idr, handle); > - if (obj) > - drm_gem_object_get(obj); > - > - spin_unlock(&filp->table_lock); > + struct drm_gem_object *obj = NULL; > > + objects_lookup(filp, &handle, 1, &obj); > return obj; > } > EXPORT_SYMBOL(drm_gem_object_lookup); > diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h > index 2955aaab3dca..5ee85c9eaa9d 100644 > --- a/include/drm/drm_gem.h > +++ b/include/drm/drm_gem.h > @@ -381,6 +381,8 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj); > void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, > bool dirty, bool accessed); > > +int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles, > + int count, struct drm_gem_object ***objs_out); > struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle); > long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, > bool wait_all, unsigned long timeout); > -- > 2.19.1 > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel