LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
To: Rob Herring <robh@kernel.org>
Cc: dri-devel <dri-devel@lists.freedesktop.org>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	open list <linux-kernel@vger.kernel.org>,
	David Airlie <airlied@linux.ie>, Sean Paul <sean@poorly.run>,
	Alyssa Rosenzweig <alyssa@rosenzweig.io>
Subject: Re: [PATCH v3 2/3] drm: Add a drm_gem_objects_lookup helper
Date: Fri, 12 Apr 2019 16:52:15 +0200
Message-ID: <CAAObsKA_5URjKzi--uQu=AV=DZtJOuVjX2cbga+syHQUnsjsjQ@mail.gmail.com> (raw)
In-Reply-To: <20190409205427.6943-3-robh@kernel.org>

Acked-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>

On Tue, 9 Apr 2019 at 22:54, Rob Herring <robh@kernel.org> 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 <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  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

  reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 20:54 [PATCH v3 0/3] Initial Panfrost driver Rob Herring
2019-04-09 20:54 ` [PATCH v3 1/3] iommu: io-pgtable: Add ARM Mali midgard MMU page table format Rob Herring
2019-04-09 20:54 ` [PATCH v3 2/3] drm: Add a drm_gem_objects_lookup helper Rob Herring
2019-04-12 14:52   ` Tomeu Vizoso [this message]
2019-04-09 20:54 ` [PATCH v3 3/3] drm/panfrost: Add initial panfrost driver Rob Herring
2019-04-09 21:25   ` Eric Anholt
2019-04-09 21:27     ` Eric Anholt
2019-04-11 14:12   ` Steven Price

Reply instructions:

You may reply publically 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='CAAObsKA_5URjKzi--uQu=AV=DZtJOuVjX2cbga+syHQUnsjsjQ@mail.gmail.com' \
    --to=tomeu.vizoso@collabora.com \
    --cc=airlied@linux.ie \
    --cc=alyssa@rosenzweig.io \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=robh@kernel.org \
    --cc=sean@poorly.run \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git