drm/amdgpu: cleanup static CSA handling
Subsystems (2)
PATCH 1/5 drm/amdgpu: cleanup static CSA handling
From: Christian König <[email protected]>
Move the CSA bo_va from the VM to the fpriv structure.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 25 ++++++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 -- 6 files changed, 20 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -750,6 +750,7 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);struct amdgpu_fpriv {struct amdgpu_vm vm;struct amdgpu_bo_va *prt_va; +struct amdgpu_bo_va *csa_va;struct mutex bo_list_lock;struct idr bo_list_handles;struct amdgpu_ctx_mgr ctx_mgr;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
@@ -777,7 +777,8 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)if (amdgpu_sriov_vf (adev)) {struct dma_fence *f; - bo_va = vm->csa_bo_va; + + bo_va = fpriv->csa_va;BUG_ON (!bo_va); r =amdgpu_vm_bo_update (adev, bo_va, false);if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -3
@@ -841,7 +841,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) }if (amdgpu_sriov_vf (adev)) { - r =amdgpu_map_static_csa (adev, &fpriv->vm); + r =amdgpu_map_static_csa (adev, &fpriv->vm, &fpriv->csa_va);if (r) goto out_suspend; }
@@ -894,8 +894,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,if (amdgpu_sriov_vf (adev)) {/* TODO: how to handle reserve failure */ BUG_ON (amdgpu_bo_reserve (adev->virt.csa_obj, true)); -amdgpu_vm_bo_rmv (adev, fpriv->vm.csa_bo_va); - fpriv->vm.csa_bo_va =NULL ; +amdgpu_vm_bo_rmv (adev, fpriv->csa_va); + fpriv->csa_va =NULL ;amdgpu_bo_unreserve (adev->virt.csa_obj); }
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -13
@@ -46,14 +46,14 @@ int amdgpu_allocate_static_csa(struct amdgpu_device *adev)* address within META_DATA init package to support SRIOV gfx preemption. */ -int amdgpu_map_static_csa (struct amdgpu_device *adev,struct amdgpu_vm *vm) +int amdgpu_map_static_csa (struct amdgpu_device *adev,struct amdgpu_vm *vm, +struct amdgpu_bo_va **bo_va) { -int r; -struct amdgpu_bo_va *bo_va;struct ww_acquire_ctx ticket;struct list_head list;struct amdgpu_bo_list_entry pd;struct ttm_validate_buffer csa_tv; +int r;INIT_LIST_HEAD (&list);INIT_LIST_HEAD (&csa_tv.head);
@@ -69,34 +69,33 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm)return r; } - bo_va =amdgpu_vm_bo_add (adev, vm, adev->virt.csa_obj); -if (!bo_va) { + *bo_va =amdgpu_vm_bo_add (adev, vm, adev->virt.csa_obj); +if (!*bo_va) {ttm_eu_backoff_reservation (&ticket, &list);DRM_ERROR ("failed to create bo_va for static CSA\n" );return -ENOMEM ; } - r =amdgpu_vm_alloc_pts (adev, bo_va->vm,AMDGPU_CSA_VADDR , -AMDGPU_CSA_SIZE ); + r =amdgpu_vm_alloc_pts (adev, (*bo_va)->vm,AMDGPU_CSA_VADDR , +AMDGPU_CSA_SIZE );if (r) {DRM_ERROR ("failed to allocate pts for static CSA, err=%d\n" , r); -amdgpu_vm_bo_rmv (adev, bo_va); +amdgpu_vm_bo_rmv (adev, *bo_va);ttm_eu_backoff_reservation (&ticket, &list);return r; } - r =amdgpu_vm_bo_map (adev, bo_va,AMDGPU_CSA_VADDR ,0 ,AMDGPU_CSA_SIZE , -AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE | -AMDGPU_PTE_EXECUTABLE ); + r =amdgpu_vm_bo_map (adev, *bo_va,AMDGPU_CSA_VADDR ,0 ,AMDGPU_CSA_SIZE , +AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE | +AMDGPU_PTE_EXECUTABLE );if (r) {DRM_ERROR ("failed to do bo_map on static CSA, err=%d\n" , r); -amdgpu_vm_bo_rmv (adev, bo_va); +amdgpu_vm_bo_rmv (adev, *bo_va);ttm_eu_backoff_reservation (&ticket, &list);return r; } - vm->csa_bo_va = bo_va;ttm_eu_backoff_reservation (&ticket, &list);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +2 -1
@@ -90,7 +90,8 @@ static inline bool is_virtual_machine(void)struct amdgpu_vm ;int amdgpu_allocate_static_csa (struct amdgpu_device *adev); -int amdgpu_map_static_csa (struct amdgpu_device *adev,struct amdgpu_vm *vm); +int amdgpu_map_static_csa (struct amdgpu_device *adev,struct amdgpu_vm *vm, +struct amdgpu_bo_va **bo_va);void amdgpu_virt_init_setting (struct amdgpu_device *adev);uint32_t amdgpu_virt_kiq_rreg (struct amdgpu_device *adev,uint32_t reg);void amdgpu_virt_kiq_wreg (struct amdgpu_device *adev,uint32_t reg,uint32_t v);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -2
@@ -141,8 +141,6 @@ struct amdgpu_vm {u64 client_id;/* dedicated to vm */ struct amdgpu_vm_id *reserved_vmid[AMDGPU_MAX_VMHUBS ]; -/* each VM will map on CSA */ -struct amdgpu_bo_va *csa_bo_va;/* Flag to indicate if VM tables are updated by CPU or GPU (SDMA) */ bool use_cpu_for_update;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1502205993-2158-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
PATCH 2/5 drm/amdgpu: remove superflous amdgpu_bo_kmap in the VM
From: Christian König <[email protected]>
We now properly kmap all BOs after validation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -19
@@ -1264,15 +1264,14 @@ void amdgpu_vm_get_entry(struct amdgpu_pte_update_params *p, uint64_t addr,* * Check if we can update the PD with a huge page. */ -static int amdgpu_vm_handle_huge_pages (struct amdgpu_pte_update_params *p, -struct amdgpu_vm_pt *entry, -struct amdgpu_vm_pt *parent, -unsigned nptes,uint64_t dst, -uint64_t flags) +static void amdgpu_vm_handle_huge_pages (struct amdgpu_pte_update_params *p, +struct amdgpu_vm_pt *entry, +struct amdgpu_vm_pt *parent, +unsigned nptes,uint64_t dst, +uint64_t flags) {bool use_cpu_update = (p->func == amdgpu_vm_cpu_set_ptes);uint64_t pd_addr, pde; -int r;/* In the case of a mixed PT the PDE must point to it*/ if (p->adev->asic_type < CHIP_VEGA10 ||
@@ -1289,16 +1288,13 @@ static int amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->addr == dst && entry->huge_page == !!(flags &AMDGPU_PDE_PTE )) -return 0 ; +return ; entry->addr = dst; entry->huge_page = !!(flags &AMDGPU_PDE_PTE );if (use_cpu_update) { - r =amdgpu_bo_kmap (parent->bo, (void *)&pd_addr); -if (r) -return r; - + pd_addr = (unsigned long )amdgpu_bo_kptr (parent->bo); pde = pd_addr + (entry - parent->entries) *8 ;amdgpu_vm_cpu_set_ptes (p, pde, dst,1 ,0 , flags); }else {
@@ -1311,8 +1307,6 @@ static int amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p, pde = pd_addr + (entry - parent->entries) *8 ;amdgpu_vm_do_set_ptes (p, pde, dst,1 ,0 , flags); } - -return 0 ; }/**
@@ -1339,7 +1333,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,struct amdgpu_bo *pt;unsigned nptes;bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes); -int r;/* walk over the address space and update the page tables */ for (addr = start; addr < end; addr += nptes,
@@ -1355,11 +1348,8 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,else nptes =AMDGPU_VM_PTE_COUNT (adev) - (addr & mask); - r =amdgpu_vm_handle_huge_pages (params, entry, parent, - nptes, dst, flags); -if (r) -return r; - +amdgpu_vm_handle_huge_pages (params, entry, parent, + nptes, dst, flags);if (entry->huge_page)continue ;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/5 drm/amdgpu: drop the extra VM huge page flag
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Just add the flags to the addr field as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 - 2 files changed, 6 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6 -9
@@ -330,7 +330,6 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, entry->bo = pt; entry->addr =0 ; - entry->huge_page = false; }if (level < adev->vm_manager.num_level) {
@@ -1082,11 +1081,11 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, pt =amdgpu_bo_gpu_offset (bo); pt =amdgpu_gart_get_vm_pde (adev, pt); -if (parent->entries[pt_idx].addr == pt || - parent->entries[pt_idx].huge_page) +if ((parent->entries[pt_idx].addr &AMDGPU_PDE_PTE ) || + parent->entries[pt_idx].addr == (pt |AMDGPU_PTE_VALID ))continue ; - parent->entries[pt_idx].addr = pt; + parent->entries[pt_idx].addr = pt |AMDGPU_PTE_VALID ; pde = pd_addr + pt_idx *8 ; if (((last_pde + 8 * count) != pde) ||
@@ -1286,12 +1285,10 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p, flags |=AMDGPU_PDE_PTE ; } -if (entry->addr == dst && - entry->huge_page == !!(flags &AMDGPU_PDE_PTE )) +if (entry->addr == (dst | flags))return ; - entry->addr = dst; - entry->huge_page = !!(flags &AMDGPU_PDE_PTE ); + entry->addr = (dst | flags);if (use_cpu_update) { pd_addr = (unsigned long )amdgpu_bo_kptr (parent->bo);
@@ -1350,7 +1347,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,amdgpu_vm_handle_huge_pages (params, entry, parent, nptes, dst, flags); -if (entry->huge_page) +if (entry->addr &AMDGPU_PDE_PTE )continue ; pt = entry->bo;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -1
@@ -103,7 +103,6 @@ struct amdgpu_bo_list_entry;struct amdgpu_vm_pt {struct amdgpu_bo *bo;uint64_t addr; -bool huge_page;/* array of page tables, one for each directory entry */ struct amdgpu_vm_pt *entries;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/5 drm/amdgpu: separate bo_va structure
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Split that into vm_bo_base and bo_va to allow other uses as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 14 ++---- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 81 ++++++++++++++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 12 +++++ 7 files changed, 66 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -2
@@ -1401,7 +1401,7 @@ amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, addr > mapping->last)continue ; - *bo = lobj->bo_va->bo; + *bo = lobj->bo_va->base.bo;return mapping; }
@@ -1410,7 +1410,7 @@ amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser, addr > mapping->last)continue ; - *bo = lobj->bo_va->bo; + *bo = lobj->bo_va->base.bo;return mapping; } }
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -2
@@ -623,7 +623,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,switch (args->operation) {case AMDGPU_VA_OP_MAP : - r =amdgpu_vm_alloc_pts (adev, bo_va->vm, args->va_address, + r =amdgpu_vm_alloc_pts (adev, bo_va->base.vm, args->va_address, args->map_size);if (r) goto error_backoff;
@@ -643,7 +643,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, args->map_size);break ;case AMDGPU_VA_OP_REPLACE : - r =amdgpu_vm_alloc_pts (adev, bo_va->vm, args->va_address, + r =amdgpu_vm_alloc_pts (adev, bo_va->base.vm, args->va_address, args->map_size);if (r) goto error_backoff;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4 -10
@@ -33,6 +33,7 @@#define AMDGPU_BO_INVALID_OFFSET LONG_MAX +/* bo virtual addresses in a vm */ struct amdgpu_bo_va_mapping {struct list_head list;struct rb_node rb;
@@ -43,26 +44,19 @@ struct amdgpu_bo_va_mapping {uint64_t flags; }; -/* bo virtual addresses in a specific vm */ +/* User space allocated BO in a VM */ struct amdgpu_bo_va { +struct amdgpu_vm_bo_base base; +/* protected by bo being reserved */ -struct list_head bo_list;struct dma_fence *last_pt_update;unsigned ref_count; -/* protected by vm mutex and spinlock */ -struct list_head vm_status; -/* mappings for this bo_va */ struct list_head invalids;struct list_head valids; - -/* constant after initialization */ -struct amdgpu_vm *vm; -struct amdgpu_bo *bo; }; -struct amdgpu_bo {/* Protected by tbo.reserved */ u32 prefered_domains;
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +2 -2
@@ -228,7 +228,7 @@ TRACE_EVENT(amdgpu_vm_bo_map, ),TP_fast_assign ( - __entry->bo = bo_va ? bo_va->bo : NULL; + __entry->bo = bo_va ? bo_va->base.bo : NULL; __entry->start = mapping->start; __entry->last = mapping->last; __entry->offset = mapping->offset;
@@ -252,7 +252,7 @@ TRACE_EVENT(amdgpu_vm_bo_unmap, ), TP_fast_assign( - __entry->bo = bo_va->bo; + __entry->bo = bo_va->base.bo; __entry->start = mapping->start; __entry->last = mapping->last; __entry->offset = mapping->offset;
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -1
@@ -76,7 +76,7 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,return -ENOMEM ; } - r =amdgpu_vm_alloc_pts (adev, (*bo_va)->vm,AMDGPU_CSA_VADDR , + r =amdgpu_vm_alloc_pts (adev, (*bo_va)->base.vm,AMDGPU_CSA_VADDR ,AMDGPU_CSA_SIZE );if (r) {DRM_ERROR ("failed to allocate pts for static CSA, err=%d\n" , r);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +43 -38
198 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +12 -0
@@ -99,6 +99,18 @@ struct amdgpu_bo_list_entry;#define AMDGPU_VM_USE_CPU_FOR_GFX (1 << 0)#define AMDGPU_VM_USE_CPU_FOR_COMPUTE (1 << 1) +/* base structure for tracking BO usage in a VM */ +struct amdgpu_vm_bo_base { +/* constant after initialization */ +struct amdgpu_vm *vm; +struct amdgpu_bo *bo; + +/* protected by bo being reserved */ +struct list_head bo_list; + +/* protected by spinlock */ +struct list_head vm_status; +};struct amdgpu_vm_pt {struct amdgpu_bo *bo;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/5 drm/amdgpu: rename VM invalidated to moved
In reply to a message not in the archiveFrom: Christian König <[email protected]>
That better describes what happens here with the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -815,7 +815,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) } - r =amdgpu_vm_clear_invalids (adev, vm, &p->job->sync); + r =amdgpu_vm_clear_moved (adev, vm, &p->job->sync);if (amdgpu_vm_debug && p->bo_list) {/* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -8
@@ -1979,25 +1979,25 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev, }/** -* amdgpu_vm_clear_invalids - clear invalidated BOs in the PT +* amdgpu_vm_clear_moved - clear moved BOs in the PT * * @adev: amdgpu_device pointer * @vm: requested vm * -* Make sure all invalidated BOs are cleared in the PT. +* Make sure all moved BOs are cleared in the PT. * Returns 0 for success. * * PTs have to be reserved and mutex must be locked! */ -int amdgpu_vm_clear_invalids (struct amdgpu_device *adev, -struct amdgpu_vm *vm,struct amdgpu_sync *sync) +int amdgpu_vm_clear_moved (struct amdgpu_device *adev,struct amdgpu_vm *vm, +struct amdgpu_sync *sync) {struct amdgpu_bo_va *bo_va =NULL ;int r =0 ;spin_lock (&vm->status_lock); -while (!list_empty (&vm->invalidated)) { - bo_va =list_first_entry (&vm->invalidated, +while (!list_empty (&vm->moved)) { + bo_va =list_first_entry (&vm->moved, struct amdgpu_bo_va, base.vm_status);spin_unlock (&vm->status_lock);
@@ -2392,7 +2392,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,spin_lock (&bo_base->vm->status_lock);if (list_empty (&bo_base->vm_status))list_add (&bo_base->vm_status, - &bo_base->vm->invalidated); + &bo_base->vm->moved);spin_unlock (&bo_base->vm->status_lock); } }
@@ -2461,7 +2461,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) vm->reserved_vmid[i] =NULL ;spin_lock_init (&vm->status_lock); -INIT_LIST_HEAD (&vm->invalidated); +INIT_LIST_HEAD (&vm->moved);INIT_LIST_HEAD (&vm->cleared);INIT_LIST_HEAD (&vm->freed);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -3
@@ -129,7 +129,7 @@ struct amdgpu_vm {spinlock_t status_lock;/* BOs moved, but not yet updated in the PT */ -struct list_head invalidated; +struct list_head moved;/* BOs cleared in the PT because of a move */ struct list_head cleared;
@@ -247,8 +247,8 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev,int amdgpu_vm_clear_freed (struct amdgpu_device *adev,struct amdgpu_vm *vm,struct dma_fence **fence); -int amdgpu_vm_clear_invalids (struct amdgpu_device *adev,struct amdgpu_vm *vm, -struct amdgpu_sync *sync); +int amdgpu_vm_clear_moved (struct amdgpu_device *adev,struct amdgpu_vm *vm, +struct amdgpu_sync *sync);int amdgpu_vm_bo_update (struct amdgpu_device *adev,struct amdgpu_bo_va *bo_va,bool clear);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx