drm: Clean up mmap for TTM-based GEM drivers
Subsystems (6)
Thomas Zimmermann
maintainerv4 cover drm: Clean up mmap for TTM-based GEM drivers
Implement mmap via struct drm_gem_object_functions.mmap in amdgpu, radeon and nouveau. This allows for using common DRM helpers for the mmap-related callbacks in struct file_operations and struct drm_driver. The drivers have their own vm_ops, which are now set automatically by the DRM core functions. The code in each driver's verify_access becomes part of the driver's new mmap implementation.
With the GEM drivers converted, vmwgfx is the only user of ttm_bo_mmap() and related infrastructure. So move everything into vmwgfx and delete the rsp code from TTM.
This touches several drivers. Preferably everything would be merged at once via drm-misc-next.
v4:
* rebase on top of amdgpu hot-unplug changes
v3:
* tidy up the new mmap functions in amdgpu and radeon (Christian)
v2:
* removal of amdgpu fbdev mmap already merged (Christian)
* rebase on top of amdgpu fixes [1] (Felix)
* replace pr_err() with drm_err() in vmwgfx patch (Zack)
* several typos
[1] https://patchwork.freedesktop.org/series/88822/
Thomas Zimmermann (7):
drm/ttm: Don't override vm_ops callbacks, if set drm/amdgpu: Implement mmap as GEM object function drm/radeon: Implement mmap as GEM object function drm/nouveau: Implement mmap as GEM object function drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver drm/vmwgfx: Inline vmw_verify_access() drm/ttm: Remove ttm_bo_mmap() and friends
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 46 ------------- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 55 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 75 --------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 - drivers/gpu/drm/nouveau/nouveau_bo.c | 10 --- drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 36 ++++++++++ drivers/gpu/drm/nouveau/nouveau_ttm.c | 49 -------------- drivers/gpu/drm/nouveau/nouveau_ttm.h | 1 - drivers/gpu/drm/radeon/radeon_drv.c | 3 +- drivers/gpu/drm/radeon/radeon_gem.c | 49 ++++++++++++++ drivers/gpu/drm/radeon/radeon_ttm.c | 65 ------------------ drivers/gpu/drm/radeon/radeon_ttm.h | 1 - drivers/gpu/drm/ttm/ttm_bo_vm.c | 60 ++--------------- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 9 --- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 53 ++++++++++++++- include/drm/ttm/ttm_bo_api.h | 13 ---- include/drm/ttm/ttm_device.h | 15 ----- 20 files changed, 202 insertions(+), 348 deletions(-)
base-commit: 28dddc0c90bc6464be4c5e3224a293c022564a4e
prerequisite-patch-id: c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24 --
2.31.1
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Thomas Zimmermann
maintainerPATCH v4 1/7 drm/ttm: Don't override vm_ops callbacks, if set
Drivers may want to set their own callbacks for a VM area. Only set TTM's callbacks if the vm_ops field is clear.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +6 -1
@@ -586,7 +586,12 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_device *bdev,static void ttm_bo_mmap_vma_setup (struct ttm_buffer_object *bo,struct vm_area_struct *vma) { - vma->vm_ops = &ttm_bo_vm_ops; +/* +* Drivers may want to override the vm_ops field. Otherwise we +* use TTM's default callbacks. +*/ +if (!vma->vm_ops) + vma->vm_ops = &ttm_bo_vm_ops;/* * Note: We're transferring the bo reference to
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Thomas Zimmermann
maintainerPATCH v4 2/7 drm/amdgpu: Implement mmap as GEM object function
In reply to Thomas ZimmermannMoving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks.
This change resolves several inconsistencies between regular mmap and prime-based mmap. The vm_ops field in vma is now set for all mmap'ed areas. Previously it way only set for regular mmap calls, prime-based mmap used TTM's default vm_ops. The function amdgpu_verify_access() is no longer being called and therefore removed by this patch.
As a side effect, amdgpu_ttm_vm_ops and amdgpu_ttm_fault() are now implemented in amdgpu's GEM code.
v4:
* rebased
v3:
* rename mmap function to amdgpu_gem_object_mmap() (Christian)
* remove unnecessary checks from mmap (Christian)
v2:
* rename amdgpu_ttm_vm_ops and amdgpu_ttm_fault() to amdgpu_gem_vm_ops and amdgpu_gem_fault() (Christian)
* the check for kfd_bo has meanwhile been removed
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 46 ------------- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 55 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 75 --------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 - 6 files changed, 57 insertions(+), 126 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +0 -46
@@ -42,52 +42,6 @@#include <linux/pci-p2pdma.h> #include <linux/pm_runtime.h> -/** -* amdgpu_gem_prime_mmap - &drm_driver.gem_prime_mmap implementation -* @obj: GEM BO -* @vma: Virtual memory area -* -* Sets up a userspace mapping of the BO's memory in the given -* virtual memory area. -* -* Returns: -* 0 on success or a negative error code on failure. -*/ -int amdgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma) -{ -struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); -struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -unsigned asize =amdgpu_bo_size (bo); -int ret; - -if (!vma->vm_file) -return -ENODEV ; - -if (adev ==NULL ) -return -ENODEV ; - -/* Check for valid size. */ -if (asize < vma->vm_end - vma->vm_start) -return -EINVAL ; - -if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || - (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { -return -EPERM ; - } - vma->vm_pgoff +=amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ; - -/* prime mmap does not need to check access, so allow here */ - ret =drm_vma_node_allow (&obj->vma_node, vma->vm_file->private_data); -if (ret) -return ret; - - ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); -drm_vma_node_revoke (&obj->vma_node, vma->vm_file->private_data); - -return ret; -} -static int __dma_resv_make_exclusive (struct dma_resv *obj) {
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h +0 -2
@@ -31,8 +31,6 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf);bool amdgpu_dmabuf_is_xgmi_accessible (struct amdgpu_device *adev,struct amdgpu_bo *bo); -int amdgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma);extern const struct dma_buf_ops amdgpu_dmabuf_ops;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -2
@@ -1691,7 +1691,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .flush = amdgpu_flush, .release = drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, - .mmap = amdgpu_mmap, + .mmap = drm_gem_mmap, .poll = drm_poll, .read = drm_read,#ifdef CONFIG_COMPAT
@@ -1758,7 +1758,7 @@ static const struct drm_driver amdgpu_kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = amdgpu_gem_prime_import, - .gem_prime_mmap = amdgpu_gem_prime_mmap, + .gem_prime_mmap = drm_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +55 -0
79 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -75
99 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +0 -1
@@ -142,7 +142,6 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,struct dma_resv *resv, struct dma_fence **fence); -int amdgpu_mmap (struct file *filp,struct vm_area_struct *vma);int amdgpu_ttm_alloc_gart (struct ttm_buffer_object *bo);int amdgpu_ttm_recover_gart (struct ttm_buffer_object *tbo);uint64_t amdgpu_ttm_domain_start (struct amdgpu_device *adev,uint32_t type);
Signature · 6 lines
2.31.1 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Thomas Zimmermann
maintainerPATCH v4 3/7 drm/radeon: Implement mmap as GEM object function
In reply to Thomas ZimmermannMoving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks.
This change also allows to support prime-based mmap via DRM's helper drm_gem_prime_mmap().
Permission checks are implemented by drm_gem_mmap(), with an additional check for radeon_ttm_tt_has_userptr() in the GEM object function. The function radeon_verify_access() is now unused and has thus been removed.
As a side effect, radeon_ttm_vm_ops and radeon_ttm_fault() are now implemented in amdgpu's GEM code.
v3:
* remove unnecessary checks from mmap (Christian)
v2:
* rename radeon_ttm_vm_ops and radeon_ttm_fault() to radeon_gem_vm_ops and radeon_gem_fault() (Christian)
* fix commit description (Alex)
--- drivers/gpu/drm/radeon/radeon_drv.c | 3 +- drivers/gpu/drm/radeon/radeon_gem.c | 49 ++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_ttm.c | 65 ----------------------------- drivers/gpu/drm/radeon/radeon_ttm.h | 1 - 4 files changed, 51 insertions(+), 67 deletions(-)
drivers/gpu/drm/radeon/radeon_drv.c +2 -1
@@ -545,7 +545,7 @@ static const struct file_operations radeon_driver_kms_fops = { .open = drm_open, .release = drm_release, .unlocked_ioctl = radeon_drm_ioctl, - .mmap = radeon_mmap, + .mmap = drm_gem_mmap, .poll = drm_poll, .read = drm_read,#ifdef CONFIG_COMPAT
@@ -620,6 +620,7 @@ static const struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import_sg_table = radeon_gem_prime_import_sg_table, + .gem_prime_mmap = drm_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,
drivers/gpu/drm/radeon/radeon_gem.c +49 -0
67 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_ttm.c +0 -65
83 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_ttm.h +0 -1
@@ -32,6 +32,5 @@ struct radeon_device;int radeon_ttm_init (struct radeon_device *rdev);void radeon_ttm_fini (struct radeon_device *rdev); -int radeon_mmap (struct file *filp,struct vm_area_struct *vma);#endif /* __RADEON_TTM_H__ */
Signature · 6 lines
2.31.1 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Thomas Zimmermann
maintainerPATCH v4 4/7 drm/nouveau: Implement mmap as GEM object function
In reply to Thomas ZimmermannMoving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks.
The GEM object function is provided by GEM TTM helpers. Nouveau's implementation of verify_access is unused and has been removed. Access permissions are validated by the DRM helpers.
As a side effect, nouveau_ttm_vm_ops and nouveau_ttm_fault() are now implemented in nouveau's GEM code.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 10 ------ drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 36 ++++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_ttm.c | 49 --------------------------- drivers/gpu/drm/nouveau/nouveau_ttm.h | 1 - 5 files changed, 38 insertions(+), 61 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -10
@@ -1050,15 +1050,6 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,return ret; } -static int -nouveau_bo_verify_access (struct ttm_buffer_object *bo,struct file *filp) -{ -struct nouveau_bo *nvbo =nouveau_bo (bo); - -return drm_vma_node_verify_access (&nvbo->bo.base.vma_node, - filp->private_data); -} -static void nouveau_ttm_io_mem_free_locked (struct nouveau_drm *drm,struct ttm_resource *reg)
@@ -1331,7 +1322,6 @@ struct ttm_device_funcs nouveau_bo_driver = { .evict_flags = nouveau_bo_evict_flags, .delete_mem_notify = nouveau_bo_delete_mem_notify, .move = nouveau_bo_move, - .verify_access = nouveau_bo_verify_access, .io_mem_reserve = &nouveau_ttm_io_mem_reserve, .io_mem_free = &nouveau_ttm_io_mem_free, };
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -1
@@ -1179,7 +1179,7 @@ nouveau_driver_fops = { .open = drm_open, .release = drm_release, .unlocked_ioctl = nouveau_drm_ioctl, - .mmap = nouveau_ttm_mmap, + .mmap = drm_gem_mmap, .poll = drm_poll, .read = drm_read,#if defined(CONFIG_COMPAT )
@@ -1212,6 +1212,7 @@ driver_stub = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table, + .gem_prime_mmap = drm_gem_prime_mmap, .dumb_create = nouveau_display_dumb_create, .dumb_map_offset = drm_gem_ttm_dumb_map_offset,
drivers/gpu/drm/nouveau/nouveau_gem.c +36 -0
@@ -39,6 +39,40 @@#include <nvif/class.h> #include <nvif/push206e.h> +static vm_fault_t nouveau_ttm_fault (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; +struct ttm_buffer_object *bo = vma->vm_private_data; +pgprot_t prot; +vm_fault_t ret; + + ret =ttm_bo_vm_reserve (bo, vmf); +if (ret) +return ret; + + ret =nouveau_ttm_fault_reserve_notify (bo); +if (ret) + goto error_unlock; + +nouveau_bo_del_io_reserve_lru (bo); + prot =vm_get_page_prot (vma->vm_flags); + ret =ttm_bo_vm_fault_reserved (vmf, prot,TTM_BO_VM_NUM_PREFAULT ,1 ); +nouveau_bo_add_io_reserve_lru (bo); +if (ret ==VM_FAULT_RETRY && !(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) +return ret; + +error_unlock: +dma_resv_unlock (bo->base.resv); +return ret; +} + +static const struct vm_operations_struct nouveau_ttm_vm_ops = { + .fault = nouveau_ttm_fault, + .open = ttm_bo_vm_open, + .close = ttm_bo_vm_close, + .access = ttm_bo_vm_access +}; +void nouveau_gem_object_del (struct drm_gem_object *gem) {
@@ -180,6 +214,8 @@ const struct drm_gem_object_funcs nouveau_gem_object_funcs = { .get_sg_table = nouveau_gem_prime_get_sg_table, .vmap = drm_gem_ttm_vmap, .vunmap = drm_gem_ttm_vunmap, + .mmap = drm_gem_ttm_mmap, + .vm_ops = &nouveau_ttm_vm_ops, };int
drivers/gpu/drm/nouveau/nouveau_ttm.c +0 -49
55 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_ttm.h +0 -1
@@ -17,7 +17,6 @@ struct ttm_tt *nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo,int nouveau_ttm_init (struct nouveau_drm *drm);void nouveau_ttm_fini (struct nouveau_drm *drm); -int nouveau_ttm_mmap (struct file *,struct vm_area_struct *);int nouveau_ttm_global_init (struct nouveau_drm *);void nouveau_ttm_global_release (struct nouveau_drm *);
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Thomas Zimmermann
maintainerPATCH v4 5/7 drm/vmwgfx: Inline ttm_bo_mmap() into vmwgfx driver
In reply to Thomas ZimmermannThe 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().
v2:
* replace pr_err() with drm_err() (Zack)
--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 56 ++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +53 -3
@@ -27,6 +27,32 @@#include "vmwgfx_drv.h" +static struct ttm_buffer_object *vmw_bo_vm_lookup (struct ttm_device *bdev, +unsigned long offset, +unsigned long pages) +{ + struct vmw_private *dev_priv = container_of(bdev, struct vmw_private, bdev); +struct drm_device *drm = &dev_priv->drm; +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) +drm_err (drm,"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 +67,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 +96,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 */
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Thomas Zimmermann
maintainerPATCH v4 6/7 drm/vmwgfx: Inline vmw_verify_access()
In reply to Thomas ZimmermannVmwgfx is the only user of the TTM's verify_access callback. Inline the call and avoid the indirection through the function pointer.
--- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 9 --------- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 7 ++----- 2 files changed, 2 insertions(+), 14 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -9
@@ -661,14 +661,6 @@ static void vmw_evict_flags(struct ttm_buffer_object *bo, *placement = vmw_sys_placement; } -static int vmw_verify_access (struct ttm_buffer_object *bo,struct file *filp) -{ -struct ttm_object_file *tfile = -vmw_fpriv ((struct drm_file *)filp->private_data)->tfile; - -return vmw_user_bo_verify_access (bo, tfile); -} -static int vmw_ttm_io_mem_reserve (struct ttm_device *bdev,struct ttm_resource *mem) { struct vmw_private *dev_priv = container_of(bdev, struct vmw_private, bdev);
@@ -771,7 +763,6 @@ struct ttm_device_funcs vmw_bo_driver = { .eviction_valuable = ttm_bo_eviction_valuable, .evict_flags = vmw_evict_flags, .move = vmw_move, - .verify_access = vmw_verify_access, .swap_notify = vmw_swap_notify, .io_mem_reserve = &vmw_ttm_io_mem_reserve, };
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +2 -5
@@ -67,6 +67,7 @@ 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); +struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile;struct ttm_device *bdev = &dev_priv->bdev;struct ttm_buffer_object *bo;int ret;
@@ -78,11 +79,7 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)if (unlikely (!bo))return -EINVAL ; -if (unlikely (!bo->bdev->funcs->verify_access)) { - ret = -EPERM ; - goto out_unref; - } - ret = bo->bdev->funcs->verify_access (bo, filp); + ret =vmw_user_bo_verify_access (bo, tfile);if (unlikely (ret !=0 )) goto out_unref;
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Thomas Zimmermann
maintainerPATCH v4 7/7 drm/ttm: Remove ttm_bo_mmap() and friends
In reply to Thomas ZimmermannThe function ttm_bo_mmap is unused. Remove it and it's helpers; including the verify_access callback in struct ttm_device_funcs.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 53 --------------------------------- include/drm/ttm/ttm_bo_api.h | 13 -------- include/drm/ttm/ttm_device.h | 15 ---------- 3 files changed, 81 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -53
@@ -560,30 +560,6 @@ static const struct vm_operations_struct ttm_bo_vm_ops = { .access = ttm_bo_vm_access, }; -static struct ttm_buffer_object *ttm_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; -} -static void ttm_bo_mmap_vma_setup (struct ttm_buffer_object *bo,struct vm_area_struct *vma) {/*
@@ -611,35 +587,6 @@ static void ttm_bo_mmap_vma_setup(struct ttm_buffer_object *bo, struct vm_area_s vma->vm_flags |=VM_IO |VM_DONTEXPAND |VM_DONTDUMP ; } -int ttm_bo_mmap (struct file *filp,struct vm_area_struct *vma, -struct ttm_device *bdev) -{ -struct ttm_buffer_object *bo; -int ret; - -if (unlikely (vma->vm_pgoff <DRM_FILE_PAGE_OFFSET_START )) -return -EINVAL ; - - bo =ttm_bo_vm_lookup (bdev, vma->vm_pgoff,vma_pages (vma)); -if (unlikely (!bo)) -return -EINVAL ; - -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; - -ttm_bo_mmap_vma_setup (bo, vma); -return 0 ; -out_unref: -ttm_bo_put (bo); -return ret; -} -EXPORT_SYMBOL (ttm_bo_mmap); -int ttm_bo_mmap_obj (struct vm_area_struct *vma,struct ttm_buffer_object *bo) {ttm_bo_get (bo);
include/drm/ttm/ttm_bo_api.h +0 -13
@@ -524,19 +524,6 @@ void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct dma_buf_map *map);*/ int ttm_bo_mmap_obj (struct vm_area_struct *vma,struct ttm_buffer_object *bo); -/** -* ttm_bo_mmap - mmap out of the ttm device address space. -* -* @filp: filp as input from the mmap method. -* @vma: vma as input from the mmap method. -* @bdev: Pointer to the ttm_device with the address space manager. -* -* This function is intended to be called by the device mmap method. -* if the device address space is to be backed by the bo manager. -*/ -int ttm_bo_mmap (struct file *filp,struct vm_area_struct *vma, -struct ttm_device *bdev); -/** * ttm_bo_io *
include/drm/ttm/ttm_device.h +0 -15
@@ -161,21 +161,6 @@ struct ttm_device_funcs {struct ttm_resource *new_mem, struct ttm_place *hop); -/** -* struct ttm_bo_driver_member verify_access -* -* @bo: Pointer to a buffer object. -* @filp: Pointer to a struct file trying to access the object. -* -* Called from the map / write / read methods to verify that the -* caller is permitted to access the buffer object. -* This member may be set to NULL, which will refuse this kind of -* access for all buffer objects. -* This function should return 0 if access is granted, -EPERM otherwise. -*/ -int (*verify_access)(struct ttm_buffer_object *bo, -struct file *filp); -/** * Hook to notify driver about a resource delete. */
Signature · 6 lines
2.31.1 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Something I forgot to add is that patches 1 to 4 already have a
Am 25.05.21 um 17:10 schrieb Thomas Zimmermann:
Quoted 64 lines
Implement mmap via struct drm_gem_object_functions.mmap in amdgpu, radeon and nouveau. This allows for using common DRM helpers for the mmap-related callbacks in struct
file_operationsand structdrm_driver. The drivers have their ownvm_ops, which are now set automatically by the DRM core functions. The code in each driver'sverify_accessbecomes part of the driver's new mmap implementation.With the GEM drivers converted, vmwgfx is the only user of
ttm_bo_mmap()and related infrastructure. So move everything into vmwgfx and delete the rsp code from TTM.This touches several drivers. Preferably everything would be merged at once via drm-misc-next.
v4:
* rebase on top of amdgpu hot-unplug changes
v3:
* tidy up the new mmap functions in amdgpu and radeon (Christian)
v2:
* removal of amdgpu fbdev mmap already merged (Christian)
* rebase on top of amdgpu fixes [1] (Felix)
* replacepr_err()withdrm_err()in vmwgfx patch (Zack)
* several typos[1] https://patchwork.freedesktop.org/series/88822/
Thomas Zimmermann (7):
drm/ttm: Don't overridevm_opscallbacks, if set drm/amdgpu: Implement mmap as GEM object function drm/radeon: Implement mmap as GEM object function drm/nouveau: Implement mmap as GEM object function drm/vmwgfx: Inlinettm_bo_mmap()into vmwgfx driver drm/vmwgfx: Inlinevmw_verify_access()drm/ttm: Removettm_bo_mmap()and friendsdrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 46 ------------- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 55 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 75 --------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 - drivers/gpu/drm/nouveau/nouveau_bo.c | 10 --- drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 36 ++++++++++ drivers/gpu/drm/nouveau/nouveau_ttm.c | 49 -------------- drivers/gpu/drm/nouveau/nouveau_ttm.h | 1 - drivers/gpu/drm/radeon/radeon_drv.c | 3 +- drivers/gpu/drm/radeon/radeon_gem.c | 49 ++++++++++++++ drivers/gpu/drm/radeon/radeon_ttm.c | 65 ------------------ drivers/gpu/drm/radeon/radeon_ttm.h | 1 - drivers/gpu/drm/ttm/ttm_bo_vm.c | 60 ++--------------- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 9 --- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 53 ++++++++++++++- include/drm/ttm/ttm_bo_api.h | 13 ---- include/drm/ttm/ttm_device.h | 15 ----- 20 files changed, 202 insertions(+), 348 deletions(-)base-commit:
28dddc0c90bc6464be4c5e3224a293c022564a4e
prerequisite-patch-id:c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id:c67e5d886a47b7d0266d81100837557fda34cb24--
2.31.1
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Christian König
maintainerPatches #1-#4 are Reviewed-by: Christian König <[email protected]>
Patches #5 and #6 are Acked-by: Christian König <[email protected]>
Patch #7 already has my rb.
I would say push that to drm-misc-next ASAP.
Regards,
Christian.
Am 25.05.21 um 17:10 schrieb Thomas Zimmermann:
Quoted 58 lines
Implement mmap via struct drm_gem_object_functions.mmap in amdgpu, radeon and nouveau. This allows for using common DRM helpers for the mmap-related callbacks in struct
file_operationsand structdrm_driver. The drivers have their ownvm_ops, which are now set automatically by the DRM core functions. The code in each driver'sverify_accessbecomes part of the driver's new mmap implementation.With the GEM drivers converted, vmwgfx is the only user of
ttm_bo_mmap()and related infrastructure. So move everything into vmwgfx and delete the rsp code from TTM.This touches several drivers. Preferably everything would be merged at once via drm-misc-next.
v4:
* rebase on top of amdgpu hot-unplug changes
v3:
* tidy up the new mmap functions in amdgpu and radeon (Christian)
v2:
* removal of amdgpu fbdev mmap already merged (Christian)
* rebase on top of amdgpu fixes [1] (Felix)
* replacepr_err()withdrm_err()in vmwgfx patch (Zack)
* several typosThomas Zimmermann (7):
drm/ttm: Don't overridevm_opscallbacks, if set drm/amdgpu: Implement mmap as GEM object function drm/radeon: Implement mmap as GEM object function drm/nouveau: Implement mmap as GEM object function drm/vmwgfx: Inlinettm_bo_mmap()into vmwgfx driver drm/vmwgfx: Inlinevmw_verify_access()drm/ttm: Removettm_bo_mmap()and friendsdrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 46 ------------- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 55 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 75 --------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 - drivers/gpu/drm/nouveau/nouveau_bo.c | 10 --- drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 36 ++++++++++ drivers/gpu/drm/nouveau/nouveau_ttm.c | 49 -------------- drivers/gpu/drm/nouveau/nouveau_ttm.h | 1 - drivers/gpu/drm/radeon/radeon_drv.c | 3 +- drivers/gpu/drm/radeon/radeon_gem.c | 49 ++++++++++++++ drivers/gpu/drm/radeon/radeon_ttm.c | 65 ------------------ drivers/gpu/drm/radeon/radeon_ttm.h | 1 - drivers/gpu/drm/ttm/ttm_bo_vm.c | 60 ++--------------- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 9 --- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 53 ++++++++++++++- include/drm/ttm/ttm_bo_api.h | 13 ---- include/drm/ttm/ttm_device.h | 15 ----- 20 files changed, 202 insertions(+), 348 deletions(-)
Quoted 6 lines
base-commit:
28dddc0c90bc6464be4c5e3224a293c022564a4e
prerequisite-patch-id:c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id:c67e5d886a47b7d0266d81100837557fda34cb24--
2.31.1
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau