TTM/Nouveau cleanups
Subsystems (4)
Hi guys,
I've already send this out in September last year, but only got a response from Daniel.
Could you guys please test this and tell me what you think about it?
Basically I'm trying to remove all driver specific features from TTM which don't need to be inside the framework.
Thanks,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/2 drm/nouveau: move io_reserve_lru handling into the driver v2
From: Christian König <[email protected]>
While working on TTM cleanups I've found that the io_reserve_lru used by Nouveau is actually not working at all.
In general we should remove driver specific handling from the memory management, so this patch moves the io_reserve_lru handling into Nouveau instead.
The patch should be functional correct, but is only compile tested!
v2: don't call ttm_bo_unmap_virtual in nouveau_ttm_io_mem_reserve
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 107 ++++++++++++++++++++------ drivers/gpu/drm/nouveau/nouveau_bo.h | 3 + drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 43 ++++++++++- 4 files changed, 131 insertions(+), 24 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +84 -23
@@ -137,6 +137,7 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)struct nouveau_bo *nvbo =nouveau_bo (bo);WARN_ON (nvbo->pin_refcnt >0 ); +nouveau_bo_del_io_reserve_lru (bo);nv10_bo_put_tile_region (dev, nvbo->tile,NULL );/*
@@ -304,6 +305,7 @@ nouveau_bo_init(struct nouveau_bo *nvbo, u64 size, int align, u32 flags, nvbo->bo.mem.num_pages = size >>PAGE_SHIFT ;nouveau_bo_placement_set (nvbo, flags,0 ); +INIT_LIST_HEAD (&nvbo->io_reserve_lru); ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type, &nvbo->placement, align >> PAGE_SHIFT, false,
@@ -574,6 +576,26 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo) PAGE_SIZE, DMA_FROM_DEVICE); } +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_move_tail (&nvbo->io_reserve_lru, &drm->ttm.io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} + +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_del_init (&nvbo->io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} +int nouveau_bo_validate (struct nouveau_bo *nvbo,bool interruptible,bool no_wait_gpu)
@@ -675,8 +697,6 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, } man->func = &nouveau_vram_manager; - man->io_reserve_fastpath = false; - man->use_io_reserve_lru = true; }else { man->func = &ttm_bo_manager_func; }
@@ -1305,6 +1325,8 @@ nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,if (bo->destroy != nouveau_bo_del_ttm)return ; +nouveau_bo_del_io_reserve_lru (bo); +if (mem && new_reg->mem_type !=TTM_PL_SYSTEM && mem->mem.page == nvbo->page) {list_for_each_entry (vma, &nvbo->vma_list, head) {
@@ -1427,6 +1449,30 @@ nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) filp->private_data); } +static void +nouveau_ttm_io_mem_free_locked (struct nouveau_drm *drm,struct ttm_mem_reg *reg) +{ +struct nouveau_mem *mem =nouveau_mem (reg); + +if (!reg->bus.base) +return ;/* already freed */ + +if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { +switch (reg->mem_type) { +case TTM_PL_TT : +if (mem->kind) +nvif_object_unmap_handle (&mem->mem.object); +break ; +case TTM_PL_VRAM : +nvif_object_unmap_handle (&mem->mem.object); +break ; +default : +break ; + } + } + reg->bus.base =0 ; +} +static int nouveau_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {
@@ -1434,18 +1480,26 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg)struct nouveau_drm *drm =nouveau_bdev (bdev);struct nvkm_device *device =nvxx_device (&drm->client.device);struct nouveau_mem *mem =nouveau_mem (reg); +struct nouveau_bo *nvbo; +int ret; + +if (reg->bus.base) +return 0 ;/* already mapped */ reg->bus.addr =NULL ; reg->bus.offset =0 ; reg->bus.size = reg->num_pages <<PAGE_SHIFT ; - reg->bus.base =0 ; reg->bus.is_iomem = false;if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE ))return -EINVAL ; + +mutex_lock (&drm->ttm.io_reserve_mutex); +retry:switch (reg->mem_type) {case TTM_PL_SYSTEM :/* System memory */ -return 0 ; + ret =0 ; + goto out;case TTM_PL_TT :#if IS_ENABLED (CONFIG_AGP )if (drm->agp.bridge) {
@@ -1469,7 +1523,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) } args;u64 handle, length;u32 argc =0 ; -int ret;switch (mem->mem.object.oclass) {case NVIF_CLASS_MEM_NV50 :
@@ -1493,38 +1546,46 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) ret =nvif_object_map_handle (&mem->mem.object, &args, argc, &handle, &length); -if (ret !=1 ) -return ret ? ret : -EINVAL ; +if (ret !=1 ) { + ret = ret ? ret : -EINVAL ; + goto out; + } + ret =0 ; reg->bus.base =0 ; reg->bus.offset = handle; }break ;default : -return -EINVAL ; + ret = -EINVAL ; } -return 0 ; + +out: +if (ret == -EAGAIN ) { + nvbo =list_first_entry_or_null (&drm->ttm.io_reserve_lru, +typeof (*nvbo), + io_reserve_lru); +if (nvbo) { +list_del_init (&nvbo->io_reserve_lru); +drm_vma_node_unmap (&nvbo->bo.base.vma_node, + bdev->dev_mapping); +nouveau_ttm_io_mem_free_locked (drm, &nvbo->bo.mem); + goto retry; + } + + } +mutex_unlock (&drm->ttm.io_reserve_mutex); +return ret; }static void nouveau_ttm_io_mem_free (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {struct nouveau_drm *drm =nouveau_bdev (bdev); -struct nouveau_mem *mem =nouveau_mem (reg); -if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { -switch (reg->mem_type) { -case TTM_PL_TT : -if (mem->kind) -nvif_object_unmap_handle (&mem->mem.object); -break ; -case TTM_PL_VRAM : -nvif_object_unmap_handle (&mem->mem.object); -break ; -default : -break ; - } - } +mutex_lock (&drm->ttm.io_reserve_mutex); +nouveau_ttm_io_mem_free_locked (drm, reg); +mutex_unlock (&drm->ttm.io_reserve_mutex); } static int
drivers/gpu/drm/nouveau/nouveau_bo.h +3 -0
@@ -17,6 +17,7 @@ struct nouveau_bo {bool force_coherent;struct ttm_bo_kmap_obj kmap;struct list_head head; +struct list_head io_reserve_lru;/* protected by ttm_bo_reserve() */ struct drm_file *reserved_by;
@@ -92,6 +93,8 @@ int nouveau_bo_validate(struct nouveau_bo *, bool interruptible, bool no_wait_gpu);void nouveau_bo_sync_for_device (struct nouveau_bo *nvbo);void nouveau_bo_sync_for_cpu (struct nouveau_bo *nvbo); +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo); +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo);/* TODO: submit equivalent to TTM generic API upstream? */ static inline void __iomem *
drivers/gpu/drm/nouveau/nouveau_drv.h +2 -0
@@ -158,6 +158,8 @@ struct nouveau_drm {int type_vram;int type_host[2 ];int type_ncoh[2 ]; +struct mutex io_reserve_mutex; +struct list_head io_reserve_lru; } ttm;/* GEM interface support */
drivers/gpu/drm/nouveau/nouveau_ttm.c +42 -1
61 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 1/2] drm/nouveau: move io_reserve_lru handling into the driver v2
Quoted 11 lines · Christian König
From: Christian König <[email protected]>
While working on TTM cleanups I've found that the
io_reserve_lruused by Nouveau is actually not working at all.In general we should remove driver specific handling from the memory management, so this patch moves the
io_reserve_lruhandling into Nouveau instead.The patch should be functional correct, but is only compile tested!
NACK on this as it currently stands. It not only causes invalid io accesses somehow on module load, but while attempting to track down why, I realised there's a more severe issue. This removes the distinction between kmap() and mapping into userspace, the former of which should not be placed onto the LRU as an eviction candidate.
We *do* require the LRU, so it's not something that can just be dropped completely. There's a user report where they're getting a SIGBUS due to the bug you noticed causing it to not work right now.
Ben.
Quoted 314 lines
v2: don't call
ttm_bo_unmap_virtualinnouveau_ttm_io_mem_reserveSigned-off-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_bo.c | 107 ++++++++++++++++++++------ drivers/gpu/drm/nouveau/nouveau_bo.h | 3 + drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 43 ++++++++++- 4 files changed, 131 insertions(+), 24 deletions(-)drivers/gpu/drm/nouveau/nouveau_bo.c +84
-23@@ -137,6 +137,7 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)struct nouveau_bo *nvbo =nouveau_bo (bo);WARN_ON (nvbo->pin_refcnt >0 ); +nouveau_bo_del_io_reserve_lru (bo);nv10_bo_put_tile_region (dev, nvbo->tile,NULL );/* @@ -304,6 +305,7 @@ nouveau_bo_init(struct nouveau_bo *nvbo, u64 size, int align, u32 flags, nvbo->bo.mem.num_pages = size >>PAGE_SHIFT ;nouveau_bo_placement_set (nvbo, flags,0 ); +INIT_LIST_HEAD (&nvbo->io_reserve_lru); ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type, &nvbo->placement, align >> PAGE_SHIFT, false,@@ -574,6 +576,26 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo) PAGE_SIZE, DMA_FROM_DEVICE); } +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_move_tail (&nvbo->io_reserve_lru, &drm->ttm.io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} + +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_del_init (&nvbo->io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} +int nouveau_bo_validate (struct nouveau_bo *nvbo,bool interruptible,bool no_wait_gpu)@@ -675,8 +697,6 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, } man->func = &nouveau_vram_manager; - man->io_reserve_fastpath = false; - man->use_io_reserve_lru = true; }else { man->func = &ttm_bo_manager_func; }@@ -1305,6 +1325,8 @@ nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,if (bo->destroy != nouveau_bo_del_ttm)return ; +nouveau_bo_del_io_reserve_lru (bo); +if (mem && new_reg->mem_type !=TTM_PL_SYSTEM && mem->mem.page == nvbo->page) {list_for_each_entry (vma, &nvbo->vma_list, head) {@@ -1427,6 +1449,30 @@ nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) filp->private_data); } +static void +nouveau_ttm_io_mem_free_locked (struct nouveau_drm *drm,struct ttm_mem_reg *reg) +{ +struct nouveau_mem *mem =nouveau_mem (reg); + +if (!reg->bus.base) +return ;/* already freed */ + +if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { +switch (reg->mem_type) { +case TTM_PL_TT : +if (mem->kind) +nvif_object_unmap_handle (&mem->mem.object); +break ; +case TTM_PL_VRAM : +nvif_object_unmap_handle (&mem->mem.object); +break ; +default : +break ; + } + } + reg->bus.base =0 ; +} +static int nouveau_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {@@ -1434,18 +1480,26 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg)struct nouveau_drm *drm =nouveau_bdev (bdev);struct nvkm_device *device =nvxx_device (&drm->client.device);struct nouveau_mem *mem =nouveau_mem (reg); +struct nouveau_bo *nvbo; +int ret; + +if (reg->bus.base) +return 0 ;/* already mapped */ reg->bus.addr =NULL ; reg->bus.offset =0 ; reg->bus.size = reg->num_pages <<PAGE_SHIFT ; - reg->bus.base =0 ; reg->bus.is_iomem = false;if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE ))return -EINVAL ; + +mutex_lock (&drm->ttm.io_reserve_mutex); +retry:switch (reg->mem_type) {case TTM_PL_SYSTEM :/* System memory */ -return 0 ; + ret =0 ; + goto out;case TTM_PL_TT :#if IS_ENABLED (CONFIG_AGP )if (drm->agp.bridge) {@@ -1469,7 +1523,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) } args;u64 handle, length;u32 argc =0 ; -int ret;switch (mem->mem.object.oclass) {case NVIF_CLASS_MEM_NV50 :@@ -1493,38 +1546,46 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) ret =nvif_object_map_handle (&mem->mem.object, &args, argc, &handle, &length); -if (ret !=1 ) -return ret ? ret : -EINVAL ; +if (ret !=1 ) { + ret = ret ? ret : -EINVAL ; + goto out; + } + ret =0 ; reg->bus.base =0 ; reg->bus.offset = handle; }break ;default : -return -EINVAL ; + ret = -EINVAL ; } -return 0 ; + +out: +if (ret == -EAGAIN ) { + nvbo =list_first_entry_or_null (&drm->ttm.io_reserve_lru, +typeof (*nvbo), + io_reserve_lru); +if (nvbo) { +list_del_init (&nvbo->io_reserve_lru); +drm_vma_node_unmap (&nvbo->bo.base.vma_node, + bdev->dev_mapping); +nouveau_ttm_io_mem_free_locked (drm, &nvbo->bo.mem); + goto retry; + } + + } +mutex_unlock (&drm->ttm.io_reserve_mutex); +return ret; }static void nouveau_ttm_io_mem_free (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {struct nouveau_drm *drm =nouveau_bdev (bdev); -struct nouveau_mem *mem =nouveau_mem (reg); -if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { -switch (reg->mem_type) { -case TTM_PL_TT : -if (mem->kind) -nvif_object_unmap_handle (&mem->mem.object); -break ; -case TTM_PL_VRAM : -nvif_object_unmap_handle (&mem->mem.object); -break ; -default : -break ; - } - } +mutex_lock (&drm->ttm.io_reserve_mutex); +nouveau_ttm_io_mem_free_locked (drm, reg); +mutex_unlock (&drm->ttm.io_reserve_mutex); } static intdrivers/gpu/drm/nouveau/nouveau_bo.h +3
-0@@ -17,6 +17,7 @@ struct nouveau_bo {bool force_coherent;struct ttm_bo_kmap_obj kmap;struct list_head head; +struct list_head io_reserve_lru;/* protected by ttm_bo_reserve() */ struct drm_file *reserved_by;@@ -92,6 +93,8 @@ int nouveau_bo_validate(struct nouveau_bo *, bool interruptible, bool no_wait_gpu);void nouveau_bo_sync_for_device (struct nouveau_bo *nvbo);void nouveau_bo_sync_for_cpu (struct nouveau_bo *nvbo); +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo); +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo);/* TODO: submit equivalent to TTM generic API upstream? */ static inline void __iomem *drivers/gpu/drm/nouveau/nouveau_drv.h +2
-0@@ -158,6 +158,8 @@ struct nouveau_drm {int type_vram;int type_host[2 ];int type_ncoh[2 ]; +struct mutex io_reserve_mutex; +struct list_head io_reserve_lru; } ttm;/* GEM interface support */ drivers/gpu/drm/nouveau/nouveau_ttm.c +42
-2@@ -162,13 +162,51 @@ const struct ttm_mem_type_manager_func nv04_gart_manager = { .debug = nouveau_manager_debug }; +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; + +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 ); +if (ret ==VM_FAULT_RETRY && !(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) +return ret; + +nouveau_bo_add_io_reserve_lru (bo); + +dma_resv_unlock (bo->base.resv); + +return ret; +} + +static 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 +}; +int nouveau_ttm_mmap (struct file *filp,struct vm_area_struct *vma) {struct drm_file *file_priv = filp->private_data;struct nouveau_drm *drm =nouveau_drm (file_priv->minor->dev); +int ret; -return ttm_bo_mmap (filp, vma, &drm->ttm.bdev); + ret =ttm_bo_mmap (filp, vma, &drm->ttm.bdev); +if (ret) +return ret; + + vma->vm_ops = &nouveau_ttm_vm_ops; +return 0 ; } static int@@ -273,6 +311,9 @@ nouveau_ttm_init(struct nouveau_drm *drm)return ret; } +mutex_init (&drm->ttm.io_reserve_mutex); +INIT_LIST_HEAD (&drm->ttm.io_reserve_lru); +NV_INFO (drm,"VRAM: %d MiB\n" , (u32)(drm->gem.vram_available >>20 ));NV_INFO (drm,"GART: %d MiB\n" , (u32)(drm->gem.gart_available >>20 ));return 0 ; --2.17.1
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 1/2] drm/nouveau: move io_reserve_lru handling into the driver v2
Hi Ben,
sorry for the delayed response. Haven been rather busy recently.
Am 28.01.20 um 06:49 schrieb Ben Skeggs:
Quoted 11 lines
Quoted 9 lines · Christian König
From: Christian König <[email protected]>
While working on TTM cleanups I've found that the
io_reserve_lruused by Nouveau is actually not working at all.In general we should remove driver specific handling from the memory management, so this patch moves the
io_reserve_lruhandling into Nouveau instead.
Quoted 6 lines
Quoted 1 line
The patch should be functional correct, but is only compile tested!
NACK on this as it currently stands. It not only causes invalid io accesses somehow on module load, but while attempting to track down why, I realised there's a more severe issue. This removes the distinction between
kmap()and mapping into userspace, the former of which should not be placed onto the LRU as an eviction candidate.
Yeah, I already feared that this won't work of hand. It's just a bit hard to write stuff without being able to test it.
Quoted 3 lines
We *do* require the LRU, so it's not something that can just be dropped completely. There's a user report where they're getting a SIGBUS due to the bug you noticed causing it to not work right now.
Well that you require an LRU is obvious. But since this is completely Nouveau specificthat handling doesn't needs to be and actually should not be in TTM.
And as Daniel pointed out the current handling in the combination of TTM and Nouveau is fundamentally broken.
Userspace can either always force other applications into a SIGBUS or the page faulting into a live lock. Both of that is rather bad.
To outline how this could work correctly:
1. You split up your PCIe BAR into pages/segments of fixed size. I'm not sure what the NVidia hardware can handle, but I would use something like 2MB segments for that to match the x86 huge page size.
2. Whenever you get a page fault or a kmap request for a buffer you walk your LRU and grab a free segment.
3. kmap requests obviously are not put back on the LRU (or are skipped while grabbed). Segments for page fault requests are put on the LRU immediately again.
The idea here is that you have at least enough segments (in this example 256 MB BAR / 2 MB segment size = 128 segments) so that you always have more segments than page faults can happen at the same time.
I'm completely fine with keeping the code around for now, but as outlined above the whole handling is rather broken.
Regards,
Christian.
Quoted 316 lines
Ben.
Quoted 313 lines
v2: don't call
ttm_bo_unmap_virtualinnouveau_ttm_io_mem_reserveSigned-off-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_bo.c | 107 ++++++++++++++++++++------ drivers/gpu/drm/nouveau/nouveau_bo.h | 3 + drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 43 ++++++++++- 4 files changed, 131 insertions(+), 24 deletions(-)drivers/gpu/drm/nouveau/nouveau_bo.c +84
-23@@ -137,6 +137,7 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)struct nouveau_bo *nvbo =nouveau_bo (bo);WARN_ON (nvbo->pin_refcnt >0 ); +nouveau_bo_del_io_reserve_lru (bo);nv10_bo_put_tile_region (dev, nvbo->tile,NULL );/* @@ -304,6 +305,7 @@ nouveau_bo_init(struct nouveau_bo *nvbo, u64 size, int align, u32 flags, nvbo->bo.mem.num_pages = size >>PAGE_SHIFT ;nouveau_bo_placement_set (nvbo, flags,0 ); +INIT_LIST_HEAD (&nvbo->io_reserve_lru); ret = ttm_bo_init(nvbo->bo.bdev, &nvbo->bo, size, type, &nvbo->placement, align >> PAGE_SHIFT, false,@@ -574,6 +576,26 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo) PAGE_SIZE, DMA_FROM_DEVICE); } +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_move_tail (&nvbo->io_reserve_lru, &drm->ttm.io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} + +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo) +{ +struct nouveau_drm *drm =nouveau_bdev (bo->bdev); +struct nouveau_bo *nvbo =nouveau_bo (bo); + +mutex_lock (&drm->ttm.io_reserve_mutex); +list_del_init (&nvbo->io_reserve_lru); +mutex_unlock (&drm->ttm.io_reserve_mutex); +} +int nouveau_bo_validate (struct nouveau_bo *nvbo,bool interruptible,bool no_wait_gpu)@@ -675,8 +697,6 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, } man->func = &nouveau_vram_manager; - man->io_reserve_fastpath = false; - man->use_io_reserve_lru = true; }else { man->func = &ttm_bo_manager_func; }@@ -1305,6 +1325,8 @@ nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,if (bo->destroy != nouveau_bo_del_ttm)return ; +nouveau_bo_del_io_reserve_lru (bo); +if (mem && new_reg->mem_type !=TTM_PL_SYSTEM && mem->mem.page == nvbo->page) {list_for_each_entry (vma, &nvbo->vma_list, head) {@@ -1427,6 +1449,30 @@ nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) filp->private_data); } +static void +nouveau_ttm_io_mem_free_locked (struct nouveau_drm *drm,struct ttm_mem_reg *reg) +{ +struct nouveau_mem *mem =nouveau_mem (reg); + +if (!reg->bus.base) +return ;/* already freed */ + +if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { +switch (reg->mem_type) { +case TTM_PL_TT : +if (mem->kind) +nvif_object_unmap_handle (&mem->mem.object); +break ; +case TTM_PL_VRAM : +nvif_object_unmap_handle (&mem->mem.object); +break ; +default : +break ; + } + } + reg->bus.base =0 ; +} +static int nouveau_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {@@ -1434,18 +1480,26 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg)struct nouveau_drm *drm =nouveau_bdev (bdev);struct nvkm_device *device =nvxx_device (&drm->client.device);struct nouveau_mem *mem =nouveau_mem (reg); +struct nouveau_bo *nvbo; +int ret; + +if (reg->bus.base) +return 0 ;/* already mapped */ reg->bus.addr =NULL ; reg->bus.offset =0 ; reg->bus.size = reg->num_pages <<PAGE_SHIFT ; - reg->bus.base =0 ; reg->bus.is_iomem = false;if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE ))return -EINVAL ; + +mutex_lock (&drm->ttm.io_reserve_mutex); +retry:switch (reg->mem_type) {case TTM_PL_SYSTEM :/* System memory */ -return 0 ; + ret =0 ; + goto out;case TTM_PL_TT :#if IS_ENABLED (CONFIG_AGP )if (drm->agp.bridge) {@@ -1469,7 +1523,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) } args;u64 handle, length;u32 argc =0 ; -int ret;switch (mem->mem.object.oclass) {case NVIF_CLASS_MEM_NV50 :@@ -1493,38 +1546,46 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *reg) ret =nvif_object_map_handle (&mem->mem.object, &args, argc, &handle, &length); -if (ret !=1 ) -return ret ? ret : -EINVAL ; +if (ret !=1 ) { + ret = ret ? ret : -EINVAL ; + goto out; + } + ret =0 ; reg->bus.base =0 ; reg->bus.offset = handle; }break ;default : -return -EINVAL ; + ret = -EINVAL ; } -return 0 ; + +out: +if (ret == -EAGAIN ) { + nvbo =list_first_entry_or_null (&drm->ttm.io_reserve_lru, +typeof (*nvbo), + io_reserve_lru); +if (nvbo) { +list_del_init (&nvbo->io_reserve_lru); +drm_vma_node_unmap (&nvbo->bo.base.vma_node, + bdev->dev_mapping); +nouveau_ttm_io_mem_free_locked (drm, &nvbo->bo.mem); + goto retry; + } + + } +mutex_unlock (&drm->ttm.io_reserve_mutex); +return ret; }static void nouveau_ttm_io_mem_free (struct ttm_bo_device *bdev,struct ttm_mem_reg *reg) {struct nouveau_drm *drm =nouveau_bdev (bdev); -struct nouveau_mem *mem =nouveau_mem (reg); -if (drm->client.mem->oclass >=NVIF_CLASS_MEM_NV50 ) { -switch (reg->mem_type) { -case TTM_PL_TT : -if (mem->kind) -nvif_object_unmap_handle (&mem->mem.object); -break ; -case TTM_PL_VRAM : -nvif_object_unmap_handle (&mem->mem.object); -break ; -default : -break ; - } - } +mutex_lock (&drm->ttm.io_reserve_mutex); +nouveau_ttm_io_mem_free_locked (drm, reg); +mutex_unlock (&drm->ttm.io_reserve_mutex); } static intdrivers/gpu/drm/nouveau/nouveau_bo.h +3
-0@@ -17,6 +17,7 @@ struct nouveau_bo {bool force_coherent;struct ttm_bo_kmap_obj kmap;struct list_head head; +struct list_head io_reserve_lru;/* protected by ttm_bo_reserve() */ struct drm_file *reserved_by;@@ -92,6 +93,8 @@ int nouveau_bo_validate(struct nouveau_bo *, bool interruptible, bool no_wait_gpu);void nouveau_bo_sync_for_device (struct nouveau_bo *nvbo);void nouveau_bo_sync_for_cpu (struct nouveau_bo *nvbo); +void nouveau_bo_add_io_reserve_lru (struct ttm_buffer_object *bo); +void nouveau_bo_del_io_reserve_lru (struct ttm_buffer_object *bo);/* TODO: submit equivalent to TTM generic API upstream? */ static inline void __iomem *drivers/gpu/drm/nouveau/nouveau_drv.h +2
-0@@ -158,6 +158,8 @@ struct nouveau_drm {int type_vram;int type_host[2 ];int type_ncoh[2 ]; +struct mutex io_reserve_mutex; +struct list_head io_reserve_lru; } ttm;/* GEM interface support */ drivers/gpu/drm/nouveau/nouveau_ttm.c +42
-2@@ -162,13 +162,51 @@ const struct ttm_mem_type_manager_func nv04_gart_manager = { .debug = nouveau_manager_debug }; +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; + +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 ); +if (ret ==VM_FAULT_RETRY && !(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) +return ret; + +nouveau_bo_add_io_reserve_lru (bo); + +dma_resv_unlock (bo->base.resv); + +return ret; +} + +static 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 +}; +int nouveau_ttm_mmap (struct file *filp,struct vm_area_struct *vma) {struct drm_file *file_priv = filp->private_data;struct nouveau_drm *drm =nouveau_drm (file_priv->minor->dev); +int ret; -return ttm_bo_mmap (filp, vma, &drm->ttm.bdev); + ret =ttm_bo_mmap (filp, vma, &drm->ttm.bdev); +if (ret) +return ret; + + vma->vm_ops = &nouveau_ttm_vm_ops; +return 0 ; } static int@@ -273,6 +311,9 @@ nouveau_ttm_init(struct nouveau_drm *drm)return ret; } +mutex_init (&drm->ttm.io_reserve_mutex); +INIT_LIST_HEAD (&drm->ttm.io_reserve_lru); +NV_INFO (drm,"VRAM: %d MiB\n" , (u32)(drm->gem.vram_available >>20 ));NV_INFO (drm,"GART: %d MiB\n" , (u32)(drm->gem.gart_available >>20 ));return 0 ; --2.17.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm/ttm: remove io_reserve_lru handling
In reply to Christian KönigFrom: Christian König <[email protected]>
That is not used any more.
--- drivers/gpu/drm/ttm/ttm_bo.c | 37 +++------- drivers/gpu/drm/ttm/ttm_bo_util.c | 114 +----------------------------- drivers/gpu/drm/ttm/ttm_bo_vm.c | 33 +++------ include/drm/ttm/ttm_bo_api.h | 5 -- include/drm/ttm/ttm_bo_driver.h | 5 -- 5 files changed, 20 insertions(+), 174 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +8 -29
@@ -311,13 +311,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,int ret =0 ;if (old_is_pci || new_is_pci || - ((mem->placement & bo->mem.placement &TTM_PL_MASK_CACHING ) ==0 )) { - ret =ttm_mem_io_lock (old_man, true); -if (unlikely (ret !=0 )) - goto out_err; -ttm_bo_unmap_virtual_locked (bo); -ttm_mem_io_unlock (old_man); - } + ((mem->placement & bo->mem.placement &TTM_PL_MASK_CACHING ) ==0 )) +ttm_bo_unmap_virtual (bo);/* * Create and bind a ttm if required.
@@ -646,15 +641,12 @@ static void ttm_bo_release(struct kref *kref)struct ttm_buffer_object *bo = container_of(kref, struct ttm_buffer_object, kref);struct ttm_bo_device *bdev = bo->bdev; -struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];if (bo->bdev->driver->release_notify) bo->bdev->driver->release_notify (bo);drm_vma_offset_remove (bdev->vma_manager, &bo->base.vma_node); -ttm_mem_io_lock (man, false); -ttm_mem_io_free_vm (bo); -ttm_mem_io_unlock (man); +ttm_mem_io_free (bdev, &bo->mem);ttm_bo_cleanup_refs_or_queue (bo);kref_put (&bo->list_kref, ttm_bo_release_list); }
@@ -703,8 +695,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, evict_mem = bo->mem; evict_mem.mm_node =NULL ; - evict_mem.bus.io_reserved_vm = false; - evict_mem.bus.io_reserved_count =0 ; + evict_mem.bus.base =0 ; ret =ttm_bo_mem_space (bo, &placement, &evict_mem, ctx);if (ret) {
@@ -1155,8 +1146,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, mem.num_pages = bo->num_pages; mem.size = mem.num_pages <<PAGE_SHIFT ; mem.page_alignment = bo->mem.page_alignment; - mem.bus.io_reserved_vm = false; - mem.bus.io_reserved_count =0 ; + mem.bus.base =0 ;/* * Determine where to move the buffer. */
@@ -1301,8 +1291,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, bo->mem.num_pages = bo->num_pages; bo->mem.mm_node =NULL ; bo->mem.page_alignment = page_alignment; - bo->mem.bus.io_reserved_vm = false; - bo->mem.bus.io_reserved_count =0 ; + bo->mem.bus.base =0 ; bo->moving =NULL ; bo->mem.placement = (TTM_PL_FLAG_SYSTEM |TTM_PL_FLAG_CACHED ); bo->acc_size = acc_size;
@@ -1748,22 +1737,12 @@ bool ttm_mem_reg_is_pci(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)return true; } -void ttm_bo_unmap_virtual_locked (struct ttm_buffer_object *bo) -{ -struct ttm_bo_device *bdev = bo->bdev; - -drm_vma_node_unmap (&bo->base.vma_node, bdev->dev_mapping); -ttm_mem_io_free_vm (bo); -} -void ttm_bo_unmap_virtual (struct ttm_buffer_object *bo) {struct ttm_bo_device *bdev = bo->bdev; -struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type]; -ttm_mem_io_lock (man, false); -ttm_bo_unmap_virtual_locked (bo); -ttm_mem_io_unlock (man); +drm_vma_node_unmap (&bo->base.vma_node, bdev->dev_mapping); +ttm_mem_io_free (bdev, &bo->mem); }
drivers/gpu/drm/ttm/ttm_bo_util.c +3 -111
181 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo_vm.c +9 -24
@@ -191,8 +191,6 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,pgoff_t i;vm_fault_t ret =VM_FAULT_NOPAGE ;unsigned long address = vmf->address; -struct ttm_mem_type_manager *man = - &bdev->man[bo->mem.mem_type];/* * Refuse to fault imported pages. This should be handled
@@ -231,24 +229,17 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,if (unlikely (ret !=0 ))return ret; - err =ttm_mem_io_lock (man, true); + err =ttm_mem_io_reserve (bdev, &bo->mem);if (unlikely (err !=0 )) -return VM_FAULT_NOPAGE ; - err =ttm_mem_io_reserve_vm (bo); -if (unlikely (err !=0 )) { - ret =VM_FAULT_SIGBUS ; - goto out_io_unlock; - } +return VM_FAULT_SIGBUS ; page_offset = ((address - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff -drm_vma_node_start (&bo->base.vma_node); page_last =vma_pages (vma) + vma->vm_pgoff -drm_vma_node_start (&bo->base.vma_node); -if (unlikely (page_offset >= bo->num_pages)) { - ret =VM_FAULT_SIGBUS ; - goto out_io_unlock; - } +if (unlikely (page_offset >= bo->num_pages)) +return VM_FAULT_SIGBUS ; cvma.vm_page_prot =ttm_io_prot (bo->mem.placement, prot);if (!bo->mem.bus.is_iomem) {
@@ -260,10 +251,8 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, }; ttm = bo->ttm; -if (ttm_tt_populate (bo->ttm, &ctx)) { - ret =VM_FAULT_OOM ; - goto out_io_unlock; - } +if (ttm_tt_populate (bo->ttm, &ctx)) +return VM_FAULT_OOM ; }else {/* Iomem should not be marked encrypted */ cvma.vm_page_prot =pgprot_decrypted (cvma.vm_page_prot);
@@ -279,8 +268,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, }else { page = ttm->pages[page_offset];if (unlikely (!page && i ==0 )) { - ret =VM_FAULT_OOM ; - goto out_io_unlock; +return VM_FAULT_OOM ; }else if (unlikely (!page)) {break ; }
@@ -298,7 +286,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,/* Never error on prefaulted PTEs */ if (unlikely ((ret &VM_FAULT_ERROR ))) {if (i ==0 ) - goto out_io_unlock; +return VM_FAULT_NOPAGE ;else break ; }
@@ -307,10 +295,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,if (unlikely (++page_offset >= page_last))break ; } - ret =VM_FAULT_NOPAGE ; -out_io_unlock: -ttm_mem_io_unlock (man); -return ret; +return VM_FAULT_NOPAGE ; }EXPORT_SYMBOL (ttm_bo_vm_fault_reserved);
include/drm/ttm/ttm_bo_api.h +0 -5
@@ -62,8 +62,6 @@ struct ttm_lru_bulk_move;* @is_iomem: is this io memory ? * @size: size in byte * @offset: offset from the base address -* @io_reserved_vm: The VM system has a refcount in @io_reserved_count -* @io_reserved_count: Refcounting the numbers of callers to ttm_mem_io_reserve * * Structure indicating the bus placement of an object. */
@@ -73,11 +71,8 @@ struct ttm_bus_placement {unsigned long size;unsigned long offset;bool is_iomem; -bool io_reserved_vm; -uint64_t io_reserved_count; }; -/** * struct ttm_mem_reg *
include/drm/ttm/ttm_bo_driver.h +0 -5
@@ -609,11 +609,6 @@ void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo);*/ void ttm_bo_unmap_virtual_locked (struct ttm_buffer_object *bo); -int ttm_mem_io_reserve_vm (struct ttm_buffer_object *bo); -void ttm_mem_io_free_vm (struct ttm_buffer_object *bo); -int ttm_mem_io_lock (struct ttm_mem_type_manager *man,bool interruptible); -void ttm_mem_io_unlock (struct ttm_mem_type_manager *man); -/** * __ttm_bo_reserve: *
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel