All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qiang Yu <yuq825@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	lima@lists.freedesktop.org, David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>, Qiang Yu <yuq825@gmail.com>,
	Sean Paul <sean@poorly.run>,
	Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Subject: [PATCH v3 1/6] drm/gem: refine drm_gem_objects_lookup
Date: Mon,  7 Oct 2019 09:54:25 +0800	[thread overview]
Message-ID: <20191007015430.20829-2-yuq825@gmail.com> (raw)
In-Reply-To: <20191007015430.20829-1-yuq825@gmail.com>

Change drm_gem_objects_lookup() to not use user space bo handles
directly and add a new interface drm_gem_objects_lookup_user()
for doing the original work.

This is for driver like lima which does not pass gem bo
handles continously in an array in ioctl argument.

v2:
1. add drm_gem_objects_lookup_user
2. remove none-zero check as all caller will check before
   calling this function

v3:
improve commit comment.

Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Cc: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Suggested-by: Rob Herring <robh@kernel.org>
Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
---
 drivers/gpu/drm/drm_gem.c               | 57 +++++++++++++++++++------
 drivers/gpu/drm/panfrost/panfrost_drv.c |  6 +--
 include/drm/drm_gem.h                   |  4 +-
 3 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 6854f5867d51..a5e88c3e6d25 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -679,11 +679,11 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
 /**
  * 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
+ * @bo_handles: array of GEM object handles
  * @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
+ * Takes an array of GEM object handles and returns a newly allocated array of
  * GEM objects.
  *
  * For a single handle lookup, use drm_gem_object_lookup().
@@ -695,26 +695,56 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
  * failure. 0 is returned on success.
  *
  */
-int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
+int drm_gem_objects_lookup(struct drm_file *filp, u32 *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;
 
+	ret = objects_lookup(filp, bo_handles, count, objs);
+	if (ret)
+		kvfree(objs);
+	else
+		*objs_out = objs;
+
+	return ret;
+
+}
+EXPORT_SYMBOL(drm_gem_objects_lookup);
+
+/**
+ * drm_gem_objects_lookup_user - 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_user(struct drm_file *filp, void __user *bo_handles,
+				int count, struct drm_gem_object ***objs_out)
+{
+	int ret;
+	u32 *handles;
+
 	handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL);
-	if (!handles) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!handles)
+		return -ENOMEM;
 
 	if (copy_from_user(handles, bo_handles, count * sizeof(u32))) {
 		ret = -EFAULT;
@@ -722,15 +752,14 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
 		goto out;
 	}
 
-	ret = objects_lookup(filp, handles, count, objs);
-	*objs_out = objs;
+	ret = drm_gem_objects_lookup(filp, handles, count, objs_out);
 
 out:
 	kvfree(handles);
 	return ret;
 
 }
-EXPORT_SYMBOL(drm_gem_objects_lookup);
+EXPORT_SYMBOL(drm_gem_objects_lookup_user);
 
 /**
  * drm_gem_object_lookup - look up a GEM object from its handle
diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
index d74442d71048..486ca51d5662 100644
--- a/drivers/gpu/drm/panfrost/panfrost_drv.c
+++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
@@ -130,9 +130,9 @@ panfrost_lookup_bos(struct drm_device *dev,
 	if (!job->implicit_fences)
 		return -ENOMEM;
 
-	return drm_gem_objects_lookup(file_priv,
-				      (void __user *)(uintptr_t)args->bo_handles,
-				      job->bo_count, &job->bos);
+	return drm_gem_objects_lookup_user(file_priv,
+					   (void __user *)(uintptr_t)args->bo_handles,
+					   job->bo_count, &job->bos);
 }
 
 /**
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 6aaba14f5972..354fc8d240e4 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -387,8 +387,10 @@ 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 drm_gem_objects_lookup(struct drm_file *filp, u32 *bo_handles,
 			   int count, struct drm_gem_object ***objs_out);
+int drm_gem_objects_lookup_user(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_dma_resv_wait(struct drm_file *filep, u32 handle,
 				    bool wait_all, unsigned long timeout);
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-10-07  1:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07  1:54 [PATCH v3 0/6] drm/lima: simplify driver by using more drm helpers Qiang Yu
2019-10-07  1:54 ` Qiang Yu [this message]
2019-10-07  1:54 ` [PATCH v3 2/6] drm/v3d: use drm_gem_objects_lookup_user Qiang Yu
2019-10-07  1:54 ` [PATCH v3 3/6] drm/lima: use drm_gem_objects_lookup Qiang Yu
2019-10-07  1:54 ` [PATCH v3 4/6] drm/lima: use drm_gem_shmem_helpers Qiang Yu
2019-10-07  1:54 ` [PATCH v3 5/6] drm/lima: use drm_gem_(un)lock_reservations Qiang Yu
2019-10-07  1:54 ` [PATCH v3 6/6] drm/lima: add __GFP_NOWARN flag to all dma_alloc_wc Qiang Yu

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=20191007015430.20829-2-yuq825@gmail.com \
    --to=yuq825@gmail.com \
    --cc=airlied@linux.ie \
    --cc=alyssa.rosenzweig@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lima@lists.freedesktop.org \
    --cc=mripard@kernel.org \
    --cc=sean@poorly.run \
    --cc=tomeu.vizoso@collabora.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.