From: Thomas Zimmermann <tzimmermann@suse.de>
To: alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@linux.ie, daniel@ffwll.ch, bskeggs@redhat.com,
ray.huang@amd.com, linux-graphics-maintainer@vmware.com,
sroland@vmware.com, zackr@vmware.com, shashank.sharma@amd.com,
sam@ravnborg.org, emil.velikov@collabora.com,
Felix.Kuehling@amd.com, nirmoy.das@amd.com
Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 6/8] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver
Date: Tue, 6 Apr 2021 11:09:01 +0200 [thread overview]
Message-ID: <20210406090903.7019-7-tzimmermann@suse.de> (raw)
In-Reply-To: <20210406090903.7019-1-tzimmermann@suse.de>
The vmwgfx driver is the only remaining user of ttm_bo_mmap(). Inline
the code. The internal helper ttm_bo_vm_lookup() is now also part of
vmwgfx as vmw_bo_vm_lookup().
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 ++++++++++++++++++++++--
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
index cb9975889e2f..3eaad00668f2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
@@ -27,6 +27,30 @@
#include "vmwgfx_drv.h"
+static struct ttm_buffer_object *vmw_bo_vm_lookup(struct ttm_device *bdev,
+ unsigned long offset,
+ unsigned long pages)
+{
+ struct drm_vma_offset_node *node;
+ struct ttm_buffer_object *bo = NULL;
+
+ drm_vma_offset_lock_lookup(bdev->vma_manager);
+
+ node = drm_vma_offset_lookup_locked(bdev->vma_manager, offset, pages);
+ if (likely(node)) {
+ bo = container_of(node, struct ttm_buffer_object,
+ base.vma_node);
+ bo = ttm_bo_get_unless_zero(bo);
+ }
+
+ drm_vma_offset_unlock_lookup(bdev->vma_manager);
+
+ if (!bo)
+ pr_err("Could not find buffer object to map\n");
+
+ return bo;
+}
+
int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
{
static const struct vm_operations_struct vmw_vm_ops = {
@@ -41,10 +65,28 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
};
struct drm_file *file_priv = filp->private_data;
struct vmw_private *dev_priv = vmw_priv(file_priv->minor->dev);
- int ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev);
+ struct ttm_device *bdev = &dev_priv->bdev;
+ struct ttm_buffer_object *bo;
+ int ret;
+
+ if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET_START))
+ return -EINVAL;
+
+ bo = vmw_bo_vm_lookup(bdev, vma->vm_pgoff, vma_pages(vma));
+ if (unlikely(!bo))
+ return -EINVAL;
- if (ret)
- return ret;
+ if (unlikely(!bo->bdev->funcs->verify_access)) {
+ ret = -EPERM;
+ goto out_unref;
+ }
+ ret = bo->bdev->funcs->verify_access(bo, filp);
+ if (unlikely(ret != 0))
+ goto out_unref;
+
+ ret = ttm_bo_mmap_obj(vma, bo);
+ if (unlikely(ret != 0))
+ goto out_unref;
vma->vm_ops = &vmw_vm_ops;
@@ -52,7 +94,13 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
if (!is_cow_mapping(vma->vm_flags))
vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
+ ttm_bo_put(bo); /* release extra ref taken by ttm_bo_mmap_obj() */
+
return 0;
+
+out_unref:
+ ttm_bo_put(bo);
+ return ret;
}
/* struct vmw_validation_mem callback */
--
2.30.2
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@linux.ie, daniel@ffwll.ch, bskeggs@redhat.com,
ray.huang@amd.com, linux-graphics-maintainer@vmware.com,
sroland@vmware.com, zackr@vmware.com, shashank.sharma@amd.com,
sam@ravnborg.org, emil.velikov@collabora.com,
Felix.Kuehling@amd.com, nirmoy.das@amd.com
Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Subject: [Nouveau] [PATCH 6/8] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver
Date: Tue, 6 Apr 2021 11:09:01 +0200 [thread overview]
Message-ID: <20210406090903.7019-7-tzimmermann@suse.de> (raw)
In-Reply-To: <20210406090903.7019-1-tzimmermann@suse.de>
The vmwgfx driver is the only remaining user of ttm_bo_mmap(). Inline
the code. The internal helper ttm_bo_vm_lookup() is now also part of
vmwgfx as vmw_bo_vm_lookup().
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 ++++++++++++++++++++++--
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
index cb9975889e2f..3eaad00668f2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
@@ -27,6 +27,30 @@
#include "vmwgfx_drv.h"
+static struct ttm_buffer_object *vmw_bo_vm_lookup(struct ttm_device *bdev,
+ unsigned long offset,
+ unsigned long pages)
+{
+ struct drm_vma_offset_node *node;
+ struct ttm_buffer_object *bo = NULL;
+
+ drm_vma_offset_lock_lookup(bdev->vma_manager);
+
+ node = drm_vma_offset_lookup_locked(bdev->vma_manager, offset, pages);
+ if (likely(node)) {
+ bo = container_of(node, struct ttm_buffer_object,
+ base.vma_node);
+ bo = ttm_bo_get_unless_zero(bo);
+ }
+
+ drm_vma_offset_unlock_lookup(bdev->vma_manager);
+
+ if (!bo)
+ pr_err("Could not find buffer object to map\n");
+
+ return bo;
+}
+
int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
{
static const struct vm_operations_struct vmw_vm_ops = {
@@ -41,10 +65,28 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
};
struct drm_file *file_priv = filp->private_data;
struct vmw_private *dev_priv = vmw_priv(file_priv->minor->dev);
- int ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev);
+ struct ttm_device *bdev = &dev_priv->bdev;
+ struct ttm_buffer_object *bo;
+ int ret;
+
+ if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET_START))
+ return -EINVAL;
+
+ bo = vmw_bo_vm_lookup(bdev, vma->vm_pgoff, vma_pages(vma));
+ if (unlikely(!bo))
+ return -EINVAL;
- if (ret)
- return ret;
+ if (unlikely(!bo->bdev->funcs->verify_access)) {
+ ret = -EPERM;
+ goto out_unref;
+ }
+ ret = bo->bdev->funcs->verify_access(bo, filp);
+ if (unlikely(ret != 0))
+ goto out_unref;
+
+ ret = ttm_bo_mmap_obj(vma, bo);
+ if (unlikely(ret != 0))
+ goto out_unref;
vma->vm_ops = &vmw_vm_ops;
@@ -52,7 +94,13 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
if (!is_cow_mapping(vma->vm_flags))
vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
+ ttm_bo_put(bo); /* release extra ref taken by ttm_bo_mmap_obj() */
+
return 0;
+
+out_unref:
+ ttm_bo_put(bo);
+ return ret;
}
/* struct vmw_validation_mem callback */
--
2.30.2
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@linux.ie, daniel@ffwll.ch, bskeggs@redhat.com,
ray.huang@amd.com, linux-graphics-maintainer@vmware.com,
sroland@vmware.com, zackr@vmware.com, shashank.sharma@amd.com,
sam@ravnborg.org, emil.velikov@collabora.com,
Felix.Kuehling@amd.com, nirmoy.das@amd.com
Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 6/8] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver
Date: Tue, 6 Apr 2021 11:09:01 +0200 [thread overview]
Message-ID: <20210406090903.7019-7-tzimmermann@suse.de> (raw)
In-Reply-To: <20210406090903.7019-1-tzimmermann@suse.de>
The vmwgfx driver is the only remaining user of ttm_bo_mmap(). Inline
the code. The internal helper ttm_bo_vm_lookup() is now also part of
vmwgfx as vmw_bo_vm_lookup().
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 ++++++++++++++++++++++--
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
index cb9975889e2f..3eaad00668f2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
@@ -27,6 +27,30 @@
#include "vmwgfx_drv.h"
+static struct ttm_buffer_object *vmw_bo_vm_lookup(struct ttm_device *bdev,
+ unsigned long offset,
+ unsigned long pages)
+{
+ struct drm_vma_offset_node *node;
+ struct ttm_buffer_object *bo = NULL;
+
+ drm_vma_offset_lock_lookup(bdev->vma_manager);
+
+ node = drm_vma_offset_lookup_locked(bdev->vma_manager, offset, pages);
+ if (likely(node)) {
+ bo = container_of(node, struct ttm_buffer_object,
+ base.vma_node);
+ bo = ttm_bo_get_unless_zero(bo);
+ }
+
+ drm_vma_offset_unlock_lookup(bdev->vma_manager);
+
+ if (!bo)
+ pr_err("Could not find buffer object to map\n");
+
+ return bo;
+}
+
int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
{
static const struct vm_operations_struct vmw_vm_ops = {
@@ -41,10 +65,28 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
};
struct drm_file *file_priv = filp->private_data;
struct vmw_private *dev_priv = vmw_priv(file_priv->minor->dev);
- int ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev);
+ struct ttm_device *bdev = &dev_priv->bdev;
+ struct ttm_buffer_object *bo;
+ int ret;
+
+ if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET_START))
+ return -EINVAL;
+
+ bo = vmw_bo_vm_lookup(bdev, vma->vm_pgoff, vma_pages(vma));
+ if (unlikely(!bo))
+ return -EINVAL;
- if (ret)
- return ret;
+ if (unlikely(!bo->bdev->funcs->verify_access)) {
+ ret = -EPERM;
+ goto out_unref;
+ }
+ ret = bo->bdev->funcs->verify_access(bo, filp);
+ if (unlikely(ret != 0))
+ goto out_unref;
+
+ ret = ttm_bo_mmap_obj(vma, bo);
+ if (unlikely(ret != 0))
+ goto out_unref;
vma->vm_ops = &vmw_vm_ops;
@@ -52,7 +94,13 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
if (!is_cow_mapping(vma->vm_flags))
vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
+ ttm_bo_put(bo); /* release extra ref taken by ttm_bo_mmap_obj() */
+
return 0;
+
+out_unref:
+ ttm_bo_put(bo);
+ return ret;
}
/* struct vmw_validation_mem callback */
--
2.30.2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2021-04-06 9:09 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 9:08 [PATCH 0/8] drm: Clean up mmap for TTM-based GEM drivers Thomas Zimmermann
2021-04-06 9:08 ` Thomas Zimmermann
2021-04-06 9:08 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:08 ` [PATCH 1/8] drm/ttm: Don't override vm_ops callbacks, if set Thomas Zimmermann
2021-04-06 9:08 ` Thomas Zimmermann
2021-04-06 9:08 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:08 ` [PATCH 2/8] drm/amdgpu: Remove unused function amdgpu_bo_fbdev_mmap() Thomas Zimmermann
2021-04-06 9:08 ` Thomas Zimmermann
2021-04-06 9:08 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:43 ` Christian König
2021-04-06 9:43 ` Christian König
2021-04-06 9:43 ` [Nouveau] " Christian König
2021-04-06 10:21 ` Thomas Zimmermann
2021-04-06 10:21 ` Thomas Zimmermann
2021-04-06 10:21 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:08 ` [PATCH 3/8] drm/amdgpu: Implement mmap as GEM object function Thomas Zimmermann
2021-04-06 9:08 ` Thomas Zimmermann
2021-04-06 9:08 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:35 ` Christian König
2021-04-06 9:35 ` Christian König
2021-04-06 9:35 ` [Nouveau] " Christian König
2021-04-06 10:38 ` Thomas Zimmermann
2021-04-06 10:38 ` Thomas Zimmermann
2021-04-06 10:38 ` [Nouveau] " Thomas Zimmermann
2021-04-06 10:56 ` Christian König
2021-04-06 10:56 ` Christian König
2021-04-06 10:56 ` [Nouveau] " Christian König
2021-04-06 11:55 ` Thomas Zimmermann
2021-04-06 11:55 ` Thomas Zimmermann
2021-04-06 11:55 ` [Nouveau] " Thomas Zimmermann
2021-04-06 12:42 ` Christian König
2021-04-06 12:42 ` Christian König
2021-04-06 12:42 ` [Nouveau] " Christian König
2021-04-06 12:52 ` Thomas Zimmermann
2021-04-06 12:52 ` Thomas Zimmermann
2021-04-06 12:52 ` [Nouveau] " Thomas Zimmermann
2021-04-06 13:04 ` Christian König
2021-04-06 13:04 ` Christian König
2021-04-06 13:04 ` [Nouveau] " Christian König
2021-04-06 15:22 ` Felix Kuehling
2021-04-06 15:22 ` Felix Kuehling
2021-04-06 15:22 ` [Nouveau] " Felix Kuehling
2021-04-06 15:27 ` Felix Kuehling
2021-04-06 15:27 ` Felix Kuehling
2021-04-06 15:27 ` [Nouveau] " Felix Kuehling
2021-04-07 11:25 ` Christian König
2021-04-07 11:25 ` Christian König
2021-04-07 11:25 ` [Nouveau] " Christian König
2021-04-07 19:34 ` Felix Kuehling
2021-04-07 19:34 ` Felix Kuehling
2021-04-07 19:34 ` [Nouveau] " Felix Kuehling
2021-04-07 19:49 ` Felix Kuehling
2021-04-07 19:49 ` Felix Kuehling
2021-04-07 19:49 ` [Nouveau] " Felix Kuehling
2021-04-08 4:45 ` Thomas Zimmermann
2021-04-08 4:45 ` Thomas Zimmermann
2021-04-08 4:45 ` [Nouveau] " Thomas Zimmermann
2021-04-14 7:44 ` Thomas Zimmermann
2021-04-14 7:44 ` Thomas Zimmermann
2021-04-14 7:44 ` [Nouveau] " Thomas Zimmermann
2021-04-14 8:37 ` Felix Kuehling
2021-04-14 8:37 ` Felix Kuehling
2021-04-14 8:37 ` [Nouveau] " Felix Kuehling
2021-04-06 9:08 ` [PATCH 4/8] drm/radeon: " Thomas Zimmermann
2021-04-06 9:08 ` Thomas Zimmermann
2021-04-06 9:08 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:38 ` Christian König
2021-04-06 9:38 ` Christian König
2021-04-06 9:38 ` [Nouveau] " Christian König
2021-04-06 14:18 ` Alex Deucher
2021-04-06 14:18 ` Alex Deucher
2021-04-06 14:18 ` [Nouveau] " Alex Deucher
2021-04-06 9:09 ` [PATCH 5/8] drm/nouveau: " Thomas Zimmermann
2021-04-06 9:09 ` Thomas Zimmermann
2021-04-06 9:09 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:09 ` Thomas Zimmermann [this message]
2021-04-06 9:09 ` [PATCH 6/8] drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver Thomas Zimmermann
2021-04-06 9:09 ` [Nouveau] " Thomas Zimmermann
2021-04-07 16:52 ` Zack Rusin
2021-04-07 16:52 ` Zack Rusin
2021-04-07 16:52 ` [Nouveau] " Zack Rusin
2021-04-06 9:09 ` [PATCH 7/8] drm/vmwgfx: Inline vmw_verify_access() Thomas Zimmermann
2021-04-06 9:09 ` Thomas Zimmermann
2021-04-06 9:09 ` [Nouveau] " Thomas Zimmermann
2021-04-07 16:52 ` Zack Rusin
2021-04-07 16:52 ` Zack Rusin
2021-04-07 16:52 ` [Nouveau] " Zack Rusin
2021-04-06 9:09 ` [PATCH 8/8] drm/ttm: Remove ttm_bo_mmap() and friends Thomas Zimmermann
2021-04-06 9:09 ` Thomas Zimmermann
2021-04-06 9:09 ` [Nouveau] " Thomas Zimmermann
2021-04-06 9:40 ` Christian König
2021-04-06 9:40 ` Christian König
2021-04-06 9:40 ` [Nouveau] " Christian König
2021-04-08 11:19 ` [PATCH 0/8] drm: Clean up mmap for TTM-based GEM drivers Daniel Vetter
2021-04-08 11:19 ` Daniel Vetter
2021-04-08 11:19 ` [Nouveau] " Daniel Vetter
2021-04-08 11:38 ` Thomas Zimmermann
2021-04-08 11:38 ` Thomas Zimmermann
2021-04-08 11:38 ` [Nouveau] " Thomas Zimmermann
2021-04-08 11:42 ` Daniel Vetter
2021-04-08 11:42 ` Daniel Vetter
2021-04-08 11:42 ` [Nouveau] " Daniel Vetter
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=20210406090903.7019-7-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bskeggs@redhat.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.velikov@collabora.com \
--cc=linux-graphics-maintainer@vmware.com \
--cc=nirmoy.das@amd.com \
--cc=nouveau@lists.freedesktop.org \
--cc=ray.huang@amd.com \
--cc=sam@ravnborg.org \
--cc=shashank.sharma@amd.com \
--cc=sroland@vmware.com \
--cc=zackr@vmware.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.