All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [PATCH 3/3] drm/prime: Use anon_drm_getfile() for an internal drm struct file
Date: Wed,  6 Nov 2019 10:07:16 +0000	[thread overview]
Message-ID: <20191106100716.18181-3-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20191106100716.18181-1-chris@chris-wilson.co.uk>

Currently the drm_prime mmap fallback uses a mock struct file to provide
the file pointer into the backend mmap routine. Now that we can create
fully fledged anonymous struct file around the drm device, put it to
use.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_prime.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 0814211b0f3f..5faa63713ec8 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -709,8 +709,7 @@ EXPORT_SYMBOL(drm_gem_dmabuf_vunmap);
  */
 int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 {
-	struct drm_file *priv;
-	struct file *fil;
+	struct file *file;
 	int ret;
 
 	if (obj->funcs && obj->funcs->mmap) {
@@ -722,30 +721,21 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 		return 0;
 	}
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	fil = kzalloc(sizeof(*fil), GFP_KERNEL);
-	if (!priv || !fil) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	file = anon_drm_getfile(obj->dev->primary, O_RDWR);
+	if (IS_ERR(file))
+		return PTR_ERR(file);
 
-	/* Used by drm_gem_mmap() to lookup the GEM object */
-	priv->minor = obj->dev->primary;
-	fil->private_data = priv;
-
-	ret = drm_vma_node_allow(&obj->vma_node, priv);
+	ret = drm_vma_node_allow(&obj->vma_node, file->private_data);
 	if (ret)
 		goto out;
 
 	vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);
 
-	ret = obj->dev->driver->fops->mmap(fil, vma);
+	ret = file->f_op->mmap(file, vma);
 
-	drm_vma_node_revoke(&obj->vma_node, priv);
+	drm_vma_node_revoke(&obj->vma_node, file->private_data);
 out:
-	kfree(priv);
-	kfree(fil);
-
+	fput(file);
 	return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_mmap);
-- 
2.24.0

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

WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 3/3] drm/prime: Use anon_drm_getfile() for an internal drm struct file
Date: Wed,  6 Nov 2019 10:07:16 +0000	[thread overview]
Message-ID: <20191106100716.18181-3-chris@chris-wilson.co.uk> (raw)
Message-ID: <20191106100716.J0t5k5qCg7g_2fklaPoppQS06yqNi0elatpQsiUBW3I@z> (raw)
In-Reply-To: <20191106100716.18181-1-chris@chris-wilson.co.uk>

Currently the drm_prime mmap fallback uses a mock struct file to provide
the file pointer into the backend mmap routine. Now that we can create
fully fledged anonymous struct file around the drm device, put it to
use.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_prime.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 0814211b0f3f..5faa63713ec8 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -709,8 +709,7 @@ EXPORT_SYMBOL(drm_gem_dmabuf_vunmap);
  */
 int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 {
-	struct drm_file *priv;
-	struct file *fil;
+	struct file *file;
 	int ret;
 
 	if (obj->funcs && obj->funcs->mmap) {
@@ -722,30 +721,21 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 		return 0;
 	}
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	fil = kzalloc(sizeof(*fil), GFP_KERNEL);
-	if (!priv || !fil) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	file = anon_drm_getfile(obj->dev->primary, O_RDWR);
+	if (IS_ERR(file))
+		return PTR_ERR(file);
 
-	/* Used by drm_gem_mmap() to lookup the GEM object */
-	priv->minor = obj->dev->primary;
-	fil->private_data = priv;
-
-	ret = drm_vma_node_allow(&obj->vma_node, priv);
+	ret = drm_vma_node_allow(&obj->vma_node, file->private_data);
 	if (ret)
 		goto out;
 
 	vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);
 
-	ret = obj->dev->driver->fops->mmap(fil, vma);
+	ret = file->f_op->mmap(file, vma);
 
-	drm_vma_node_revoke(&obj->vma_node, priv);
+	drm_vma_node_revoke(&obj->vma_node, file->private_data);
 out:
-	kfree(priv);
-	kfree(fil);
-
+	fput(file);
 	return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_mmap);
-- 
2.24.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-11-06 10:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-06 10:07 [PATCH 1/3] drm: Expose a method for creating anonymous struct file around drm_minor Chris Wilson
2019-11-06 10:07 ` [Intel-gfx] " Chris Wilson
2019-11-06 10:07 ` Chris Wilson
2019-11-06 10:07 ` [PATCH 2/3] drm/i915/selftests: Wrap vm_mmap() around GEM objects Chris Wilson
2019-11-06 10:07   ` [Intel-gfx] " Chris Wilson
2019-11-06 10:07   ` Chris Wilson
2019-11-06 10:07 ` Chris Wilson [this message]
2019-11-06 10:07   ` [Intel-gfx] [PATCH 3/3] drm/prime: Use anon_drm_getfile() for an internal drm struct file Chris Wilson
2019-11-06 10:21   ` Daniel Vetter
2019-11-06 10:21     ` [Intel-gfx] " Daniel Vetter
2019-11-06 10:21     ` Daniel Vetter
2019-11-06 10:45     ` Chris Wilson
2019-11-06 10:45       ` [Intel-gfx] " Chris Wilson
2019-11-06 10:45       ` Chris Wilson
2019-11-06 13:06       ` Daniel Vetter
2019-11-06 13:06         ` [Intel-gfx] " Daniel Vetter
2019-11-06 13:17         ` Chris Wilson
2019-11-06 13:17           ` [Intel-gfx] " Chris Wilson
2019-11-06 13:17           ` Chris Wilson
2019-11-06 10:19 ` [PATCH 1/3] drm: Expose a method for creating anonymous struct file around drm_minor Daniel Vetter
2019-11-06 10:19   ` [Intel-gfx] " Daniel Vetter
2019-11-06 10:19   ` Daniel Vetter
2019-11-06 10:26   ` Chris Wilson
2019-11-06 10:26     ` [Intel-gfx] " Chris Wilson
2019-11-06 10:26     ` Chris Wilson
2019-11-06 10:42     ` Chris Wilson
2019-11-06 10:42       ` [Intel-gfx] " Chris Wilson
2019-11-06 10:42       ` Chris Wilson
2019-11-06 13:08       ` Daniel Vetter
2019-11-06 13:08         ` [Intel-gfx] " Daniel Vetter
2019-11-06 13:08         ` Daniel Vetter
2019-11-06 11:24 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " Patchwork
2019-11-06 11:24   ` [Intel-gfx] " Patchwork
2019-11-06 11:44 ` ✓ Fi.CI.BAT: success " Patchwork
2019-11-06 11:44   ` [Intel-gfx] " Patchwork
2019-11-07  8:40 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-11-07  8:40   ` [Intel-gfx] " Patchwork

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=20191106100716.18181-3-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.