drm/amdgpu: Add amdgpu_bo_is_vm_bo helper
Subsystems (2)
PATCH 1/3 drm/amdgpu: Add amdgpu_bo_is_vm_bo helper
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv == vm->root.bo->tbo.base.resv
With:
amdgpu_vm_is_bo_always_valid(vm, bo)
No functional changes.
v2:
* Rename helper and move to amdgpu_vm. (Christian)
v3:
* Use Christian's kerneldoc.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41 ++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++ 3 files changed, 29 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,return -EPERM ;if (abo->flags &AMDGPU_GEM_CREATE_VM_ALWAYS_VALID && - abo->tbo.base.resv != vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid (vm, abo))return -EPERM ; r =amdgpu_bo_reserve (abo, false);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26 -15
109 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m);int amdgpu_vm_pt_map_tables (struct amdgpu_device *adev,struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid (struct amdgpu_vm *vm,struct amdgpu_bo *bo); +/** * amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query
Signature · 1 line
2.44.0
PATCH 2/3 drm/amdgpu: Reduce mem_type to domain double indirection
From: Tvrtko Ursulin <[email protected]>
All apart from AMDGPU_GEM_DOMAIN_GTT memory domains map 1:1 to TTM placements. And the former be either AMDGPU_PL_PREEMPT or TTM_PL_TT, depending on AMDGPU_GEM_CREATE_PREEMPTIBLE.
Simplify a few places in the code which convert the TTM placement into a domain by checking against the current placement directly.
In the conversion AMDGPU_PL_PREEMPT either does not have to be handled because amdgpu_mem_type_to_domain() cannot return that value anyway.
v2:
* Remove AMDGPU_PL_PREEMPT handling.
v3:
* Rebase.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 29 +++++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -2
@@ -165,8 +165,7 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,if (r)return ERR_PTR (r); - }else if (!(amdgpu_mem_type_to_domain (bo->tbo.resource->mem_type) & -AMDGPU_GEM_DOMAIN_GTT )) { + }else if (bo->tbo.resource->mem_type !=TTM_PL_TT ) {return ERR_PTR (-EBUSY ); }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +12 -17
@@ -983,12 +983,11 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,ttm_bo_pin (&bo->tbo); - domain =amdgpu_mem_type_to_domain (bo->tbo.resource->mem_type); -if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { +if (bo->tbo.resource->mem_type ==TTM_PL_VRAM ) {atomic64_add (amdgpu_bo_size (bo), &adev->vram_pin_size);atomic64_add (amdgpu_vram_mgr_bo_visible_size (bo), &adev->visible_pin_size); - }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { + }else if (bo->tbo.resource->mem_type ==TTM_PL_TT ) {atomic64_add (amdgpu_bo_size (bo), &adev->gart_pin_size); }
@@ -1293,7 +1292,6 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,struct ttm_resource *res = bo->tbo.resource;uint64_t size =amdgpu_bo_size (bo);struct drm_gem_object *obj; -unsigned int domain;bool shared;/* Abort if the BO doesn't currently have a backing store */
@@ -1303,21 +1301,20 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo, obj = &bo->tbo.base; shared =drm_gem_object_is_shared_for_memory_stats (obj); - domain =amdgpu_mem_type_to_domain (res->mem_type); -switch (domain) { -case AMDGPU_GEM_DOMAIN_VRAM : +switch (res->mem_type) { +case TTM_PL_VRAM : stats->vram += size; -if (amdgpu_res_cpu_visible (adev, bo->tbo.resource)) +if (amdgpu_res_cpu_visible (adev, res)) stats->visible_vram += size;if (shared) stats->vram_shared += size;break ; -case AMDGPU_GEM_DOMAIN_GTT : +case TTM_PL_TT : stats->gtt += size;if (shared) stats->gtt_shared += size;break ; -case AMDGPU_GEM_DOMAIN_CPU : +case TTM_PL_SYSTEM :default : stats->cpu += size;if (shared)
@@ -1330,7 +1327,7 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,if (bo->flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) stats->requested_visible_vram += size; -if (domain !=AMDGPU_GEM_DOMAIN_VRAM ) { +if (res->mem_type !=TTM_PL_VRAM ) { stats->evicted_vram += size;if (bo->flags &AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ) stats->evicted_visible_vram += size;
@@ -1604,20 +1601,18 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)u64 size;if (dma_resv_trylock (bo->tbo.base.resv)) { -unsigned int domain; - domain =amdgpu_mem_type_to_domain (bo->tbo.resource->mem_type); -switch (domain) { -case AMDGPU_GEM_DOMAIN_VRAM : +switch (bo->tbo.resource->mem_type) { +case TTM_PL_VRAM :if (amdgpu_res_cpu_visible (adev, bo->tbo.resource)) placement ="VRAM VISIBLE" ;else placement ="VRAM" ;break ; -case AMDGPU_GEM_DOMAIN_GTT : +case TTM_PL_TT : placement ="GTT" ;break ; -case AMDGPU_GEM_DOMAIN_CPU : +case TTM_PL_SYSTEM :default : placement ="CPU" ;break ;
Signature · 1 line
2.44.0
PATCH 3/3 drm/amdgpu: Describe all object placements in debugfs
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Accurately show all placements when describing objects in debugfs, instead of bunching them up under the 'CPU' placement.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +15 -0
@@ -1612,6 +1612,21 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)case TTM_PL_TT : placement ="GTT" ;break ; +case AMDGPU_PL_GDS : + placement ="GDS" ; +break ; +case AMDGPU_PL_GWS : + placement ="GWS" ; +break ; +case AMDGPU_PL_OA : + placement ="OA" ; +break ; +case AMDGPU_PL_PREEMPT : + placement ="PREEMPTIBLE" ; +break ; +case AMDGPU_PL_DOORBELL : + placement ="DOORBELL" ; +break ;case TTM_PL_SYSTEM :default : placement ="CPU" ;
Signature · 1 line
2.44.0
Quoted 56 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv==vm->root.bo->tbo.base.resvWith:
amdgpu_vm_is_bo_always_valid(vm, bo)No functional changes.
v2:
* Rename helper and move toamdgpu_vm. (Christian)v3:
* Use Christian's kerneldoc.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Reviewed-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41 ++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++ 3 files changed, 29 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,return -EPERM ;if (abo->flags &AMDGPU_GEM_CREATE_VM_ALWAYS_VALID && - abo->tbo.base.resv != vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid (vm, abo))return -EPERM ; r =amdgpu_bo_reserve (abo, false);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -333,7 +333,7 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, base->next = bo->vm_bo; bo->vm_bo = base; -if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) +if (!amdgpu_vm_is_bo_always_valid (vm, bo))return ;dma_resv_assert_held (vm->root.bo->tbo.base.resv);@@ -1101,13 +1101,13 @@ static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va,* For now ignore BOs which are currently locked and potentially * changing their location.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va, · line 1109
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-3*/ -if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && +if (!amdgpu_vm_is_bo_always_valid (vm, bo) && !dma_resv_trylock (bo->tbo.base.resv))return ;amdgpu_bo_get_memory (bo, stats); -if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) -dma_resv_unlock (bo->tbo.base.resv); +if (amdgpu_vm_is_bo_always_valid (vm, bo))
Beware the logic inversion here - luckily no one merged it yet! I will send a respin..
Regards,
Tvrtko
Quoted 111 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-11+dma_resv_unlock (bo->tbo.base.resv); } void amdgpu_vm_get_memory(struct amdgpu_vm *vm,@@ -1203,8 +1203,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, uncached = false; } -if (clear || (bo && bo->tbo.base.resv == - vm->root.bo->tbo.base.resv)) +if (clear ||amdgpu_vm_is_bo_always_valid (vm, bo)) last_update = &vm->last_update;else last_update = &bo_va->last_pt_update;@@ -1246,7 +1245,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,* the evicted list so that it gets validated again on the * next command submission. */ -if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { +if (amdgpu_vm_is_bo_always_valid (vm, bo)) {uint32_t mem_type = bo->tbo.resource->mem_type; if (!(bo->preferred_domains &@@ -1640,10 +1639,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,if (mapping->flags &AMDGPU_PTE_PRT )amdgpu_vm_prt_get (adev); -if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && - !bo_va->base.moved) { +if (amdgpu_vm_is_bo_always_valid (vm, bo) && !bo_va->base.moved)amdgpu_vm_bo_moved (&bo_va->base); - } +trace_amdgpu_vm_bo_map (bo_va, mapping); }@@ -1942,7 +1940,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,if (before->flags &AMDGPU_PTE_PRT )amdgpu_vm_prt_get (adev); -if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && +if (amdgpu_vm_is_bo_always_valid (vm, bo) && !before->bo_va->base.moved)amdgpu_vm_bo_moved (&before->bo_va->base); }else {@@ -1957,7 +1955,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,if (after->flags &AMDGPU_PTE_PRT )amdgpu_vm_prt_get (adev); -if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv && +if (amdgpu_vm_is_bo_always_valid (vm, bo) && !after->bo_va->base.moved)amdgpu_vm_bo_moved (&after->bo_va->base); }else {@@ -2037,7 +2035,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev,if (bo) {dma_resv_assert_held (bo->tbo.base.resv); -if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) +if (amdgpu_vm_is_bo_always_valid (vm, bo))ttm_bo_set_bulk_move (&bo->tbo,NULL ); for (base = &bo_va->base.bo->vm_bo; *base;@@ -2131,7 +2129,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {struct amdgpu_vm *vm = bo_base->vm; -if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { +if (evicted &&amdgpu_vm_is_bo_always_valid (vm, bo)) {amdgpu_vm_bo_evicted (bo_base);continue ; }@@ -2142,7 +2140,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,if (bo->tbo.type == ttm_bo_type_kernel)amdgpu_vm_bo_relocated (bo_base); -else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) +else if (amdgpu_vm_is_bo_always_valid (vm, bo))amdgpu_vm_bo_moved (bo_base);else amdgpu_vm_bo_invalidated (bo_base);@@ -3006,3 +3004,16 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); } +/** +* amdgpu_vm_is_bo_always_valid - check if the BO is VM always valid +* +* @vm: VM to test against. +* @abo: BO to be tested. +* +* Returns true if the BO shares the dma_resv object with the root PD and is +* always guaranteed to be valid inside the VM. +*/ +bool amdgpu_vm_is_bo_always_valid (struct amdgpu_vm *vm,struct amdgpu_bo *bo) +{ +return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv; +}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2
-0@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m);int amdgpu_vm_pt_map_tables (struct amdgpu_device *adev,struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid (struct amdgpu_vm *vm,struct amdgpu_bo *bo); +/** * amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query
Am 06.05.24 um 18:26 schrieb Tvrtko Ursulin:
Quoted 60 lines · Tvrtko Ursulin
Quoted 58 lines
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv==vm->root.bo->tbo.base.resvWith:
amdgpu_vm_is_bo_always_valid(vm, bo)No functional changes.
v2:
* Rename helper and move toamdgpu_vm. (Christian)v3:
* Use Christian's kerneldoc.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41 ++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++3 files changed, 29 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(structdrm_gem_object *obj, return -EPERM;if (
abo->flags&AMDGPU_GEM_CREATE_VM_ALWAYS_VALID&& -abo->tbo.base.resv!=vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid(vm, abo)) return-EPERM;
r =amdgpu_bo_reserve(abo, false);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -333,7 +333,7 @@ void amdgpu_vm_bo_base_init(structamdgpu_vm_bo_base *base, base->next = bo->vm_bo; bo->vm_bo = base; - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) + if (!amdgpu_vm_is_bo_always_valid(vm, bo)) return; dma_resv_assert_held(vm->root.bo->tbo.base.resv);@@ -1101,13 +1101,13 @@ static void amdgpu_vm_bo_get_memory(structamdgpu_bo_va *bo_va, * For now ignore BOs which are currently locked and potentially * changing their location. */ - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && + if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va, · line 1109
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-2!dma_resv_trylock(bo->tbo.base.resv)) return; amdgpu_bo_get_memory(bo, stats); - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) - dma_resv_unlock(bo->tbo.base.resv); + if (amdgpu_vm_is_bo_always_valid(vm, bo))Beware the logic inversion here - luckily no one merged it yet! I will send a respin..
Let me know when that is done, I was about to merge it.
Regards,
Christian.
Quoted 112 lines
Regards,
Tvrtko
Quoted 107 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+dma_resv_unlock (bo->tbo.base.resv); } void amdgpu_vm_get_memory(struct amdgpu_vm *vm,@@ -1203,8 +1203,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, uncached = false; }- if (clear || (bo &&
bo->tbo.base.resv== -vm->root.bo->tbo.base.resv))
+ if (clear ||amdgpu_vm_is_bo_always_valid(vm, bo))last_update=&vm->last_update;
else
last_update=&bo_va->last_pt_update;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1246,7 +1245,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device*adev, struct amdgpu_bo_va *bo_va, * the evicted list so that it gets validated again on the * next command submission. */ - if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (amdgpu_vm_is_bo_always_valid(vm, bo)) { uint32_t mem_type = bo->tbo.resource->mem_type;if (!(bo->preferred_domains &
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1640,10 +1639,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, if (mapping->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&&
- !bo_va->base.moved) {
+ if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !bo_va->base.moved)amdgpu_vm_bo_moved(&bo_va->base);
- }
+
trace_amdgpu_vm_bo_map(bo_va, mapping);
}
@@ -1942,7 +1940,7 @@ int amdgpu_vm_bo_clear_mappings(structamdgpu_device*adev, if (before->flags&AMDGPU_PTE_PRT)
amdgpu_vm_prt_get(adev);
- if (bo &&bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !before->bo_va->base.moved)amdgpu_vm_bo_moved(&before->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1957,7 +1955,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev, if (after->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !after->bo_va->base.moved)amdgpu_vm_bo_moved(&after->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2037,7 +2035,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, if (bo) { dma_resv_assert_held(bo->tbo.base.resv); - if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + if (amdgpu_vm_is_bo_always_valid(vm, bo)) ttm_bo_set_bulk_move(&bo->tbo, NULL); for (base = &bo_va->base.bo->vm_bo; *base;@@ -2131,7 +2129,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) { struct amdgpu_vm *vm = bo_base->vm; - if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (evicted && amdgpu_vm_is_bo_always_valid(vm, bo)) { amdgpu_vm_bo_evicted(bo_base); continue;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -2142,7 +2140,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, if (bo->tbo.type == ttm_bo_type_kernel) amdgpu_vm_bo_relocated(bo_base); - else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + else if (amdgpu_vm_is_bo_always_valid(vm, bo)) amdgpu_vm_bo_moved(bo_base);else
amdgpu_vm_bo_invalidated(bo_base);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -3006,3 +3004,16 @@ void amdgpu_vm_update_fault_cache(structamdgpu_device *adev, xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); }+/**
+ *amdgpu_vm_is_bo_always_valid- check if the BO is VM always valid
+ *
+ * @vm: VM to test against.
+ * @abo: BO to be tested.
+ *
+ * Returns true if the BO shares thedma_resvobject with the root PD and is
+ * always guaranteed to be valid inside the VM.
+ */
+boolamdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0+{ + return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv; +}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m); int amdgpu_vm_pt_map_tables(struct amdgpu_device *adev, struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo); + /*** amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query
Quoted 70 lines · Christian König
Am 06.05.24 um 18:26 schrieb Tvrtko Ursulin:
Quoted 60 lines · Tvrtko Ursulin
Quoted 58 lines
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv==vm->root.bo->tbo.base.resvWith:
amdgpu_vm_is_bo_always_valid(vm, bo)No functional changes.
v2:
* Rename helper and move toamdgpu_vm. (Christian)v3:
* Use Christian's kerneldoc.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41 ++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++3 files changed, 29 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(structdrm_gem_object *obj, return -EPERM;if (
abo->flags&AMDGPU_GEM_CREATE_VM_ALWAYS_VALID&& -abo->tbo.base.resv!=vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid(vm, abo)) return-EPERM;
r =amdgpu_bo_reserve(abo, false);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -333,7 +333,7 @@ void amdgpu_vm_bo_base_init(structamdgpu_vm_bo_base *base, base->next = bo->vm_bo; bo->vm_bo = base; - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) + if (!amdgpu_vm_is_bo_always_valid(vm, bo)) return; dma_resv_assert_held(vm->root.bo->tbo.base.resv);@@ -1101,13 +1101,13 @@ static void amdgpu_vm_bo_get_memory(structamdgpu_bo_va *bo_va, * For now ignore BOs which are currently locked and potentially * changing their location. */ - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && + if (!amdgpu_vm_is_bo_always_valid(vm, bo) &&Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va, · line 1109
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-2!dma_resv_trylock(bo->tbo.base.resv)) return; amdgpu_bo_get_memory(bo, stats); - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) - dma_resv_unlock(bo->tbo.base.resv); + if (amdgpu_vm_is_bo_always_valid(vm, bo))Beware the logic inversion here - luckily no one merged it yet! I will send a respin..
Quoted 1 line
Let me know when that is done, I was about to merge it.
First three patches in the series https://lore.kernel.org/amd-gfx/[email protected]/ if you can pull it from there or I should resend standalone?
Please double check it though. Sorry about that I am so used to pre-merge CI we have on the i915 preventing silly mistakes such as that one.
Regards,
Tvrtko
Quoted 118 lines
Regards,
Christian.Quoted 112 lines
Regards,
Tvrtko
Quoted 107 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+dma_resv_unlock (bo->tbo.base.resv); } void amdgpu_vm_get_memory(struct amdgpu_vm *vm,@@ -1203,8 +1203,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, uncached = false; }- if (clear || (bo &&
bo->tbo.base.resv== -vm->root.bo->tbo.base.resv))
+ if (clear ||amdgpu_vm_is_bo_always_valid(vm, bo))last_update=&vm->last_update;
else
last_update=&bo_va->last_pt_update;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1246,7 +1245,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device*adev, struct amdgpu_bo_va *bo_va, * the evicted list so that it gets validated again on the * next command submission. */ - if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (amdgpu_vm_is_bo_always_valid(vm, bo)) { uint32_t mem_type = bo->tbo.resource->mem_type;if (!(bo->preferred_domains &
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1640,10 +1639,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, if (mapping->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&&
- !bo_va->base.moved) {
+ if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !bo_va->base.moved)amdgpu_vm_bo_moved(&bo_va->base);
- }
+
trace_amdgpu_vm_bo_map(bo_va, mapping);
}
@@ -1942,7 +1940,7 @@ int amdgpu_vm_bo_clear_mappings(structamdgpu_device*adev, if (before->flags&AMDGPU_PTE_PRT)
amdgpu_vm_prt_get(adev);
- if (bo &&bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !before->bo_va->base.moved)amdgpu_vm_bo_moved(&before->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1957,7 +1955,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev, if (after->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !after->bo_va->base.moved)amdgpu_vm_bo_moved(&after->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2037,7 +2035,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, if (bo) { dma_resv_assert_held(bo->tbo.base.resv); - if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + if (amdgpu_vm_is_bo_always_valid(vm, bo)) ttm_bo_set_bulk_move(&bo->tbo, NULL); for (base = &bo_va->base.bo->vm_bo; *base;@@ -2131,7 +2129,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) { struct amdgpu_vm *vm = bo_base->vm; - if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (evicted && amdgpu_vm_is_bo_always_valid(vm, bo)) { amdgpu_vm_bo_evicted(bo_base); continue;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -2142,7 +2140,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, if (bo->tbo.type == ttm_bo_type_kernel) amdgpu_vm_bo_relocated(bo_base); - else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + else if (amdgpu_vm_is_bo_always_valid(vm, bo)) amdgpu_vm_bo_moved(bo_base);else
amdgpu_vm_bo_invalidated(bo_base);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -3006,3 +3004,16 @@ void amdgpu_vm_update_fault_cache(structamdgpu_device *adev, xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); }+/**
+ *amdgpu_vm_is_bo_always_valid- check if the BO is VM always valid
+ *
+ * @vm: VM to test against.
+ * @abo: BO to be tested.
+ *
+ * Returns true if the BO shares thedma_resvobject with the root PD and is
+ * always guaranteed to be valid inside the VM.
+ */
+boolamdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0+{ + return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv; +}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m); int amdgpu_vm_pt_map_tables(struct amdgpu_device *adev, struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo); + /*** amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query
Hi Christian,
Quoted 72 lines · Tvrtko Ursulin
Quoted 71 lines · Christian König
Am 06.05.24 um 18:26 schrieb Tvrtko Ursulin:
Quoted 69 lines · Tvrtko Ursulin
Quoted 55 lines
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv==vm->root.bo->tbo.base.resvWith:
amdgpu_vm_is_bo_always_valid(vm, bo)No functional changes.
v2:
* Rename helper and move toamdgpu_vm. (Christian)v3:
* Use Christian's kerneldoc.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41
++++++++++++++++---------
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++3 files changed, 29 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(structdrm_gem_object *obj, return -EPERM;if (
abo->flags&AMDGPU_GEM_CREATE_VM_ALWAYS_VALID&& -abo->tbo.base.resv!=vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid(vm, abo)) return-EPERM;
r =amdgpu_bo_reserve(abo, false);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -333,7 +333,7 @@ void amdgpu_vm_bo_base_init(structamdgpu_vm_bo_base *base, base->next = bo->vm_bo; bo->vm_bo = base; - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) + if (!amdgpu_vm_is_bo_always_valid(vm, bo)) return; dma_resv_assert_held(vm->root.bo->tbo.base.resv);@@ -1101,13 +1101,13 @@ static void amdgpu_vm_bo_get_memory(structamdgpu_bo_va *bo_va, * For now ignore BOs which are currently locked and potentiallydrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_bo_get_memory(struct · line 1109
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-3* changing their location. */ - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && + if (!amdgpu_vm_is_bo_always_valid(vm, bo) && !dma_resv_trylock(bo->tbo.base.resv)) return; amdgpu_bo_get_memory(bo, stats); - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) - dma_resv_unlock(bo->tbo.base.resv); + if (amdgpu_vm_is_bo_always_valid(vm, bo))Beware the logic inversion here - luckily no one merged it yet! I will send a respin..
Quoted 5 lines
Quoted 1 line
Let me know when that is done, I was about to merge it.
First three patches in the series https://lore.kernel.org/amd-gfx/[email protected]/ if you can pull it from there or I should resend standalone?
Please double check it though. Sorry about that I am so used to pre-merge CI we have on the i915 preventing silly mistakes such as that one.
Small reminder on the above since you have been out - are you okay to pick up the first three patches from https://lore.kernel.org/amd-gfx/[email protected]/, if they still look okay to you? Or I should re-send them standalone?
Regards,
Tvrtko
Quoted 109 lines
Quoted 109 lines
Quoted 107 lines
Quoted 107 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+dma_resv_unlock (bo->tbo.base.resv); } void amdgpu_vm_get_memory(struct amdgpu_vm *vm,@@ -1203,8 +1203,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, uncached = false; }- if (clear || (bo &&
bo->tbo.base.resv== -vm->root.bo->tbo.base.resv))
+ if (clear ||amdgpu_vm_is_bo_always_valid(vm, bo))last_update=&vm->last_update;
else
last_update=&bo_va->last_pt_update;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1246,7 +1245,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device*adev, struct amdgpu_bo_va *bo_va, * the evicted list so that it gets validated again on the * next command submission. */ - if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (amdgpu_vm_is_bo_always_valid(vm, bo)) { uint32_t mem_type = bo->tbo.resource->mem_type;if (!(bo->preferred_domains &
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1640,10 +1639,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, if (mapping->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&&
- !bo_va->base.moved) {
+ if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !bo_va->base.moved)amdgpu_vm_bo_moved(&bo_va->base);
- }
+
trace_amdgpu_vm_bo_map(bo_va, mapping);
}
@@ -1942,7 +1940,7 @@ int amdgpu_vm_bo_clear_mappings(structamdgpu_device*adev, if (before->flags&AMDGPU_PTE_PRT)
amdgpu_vm_prt_get(adev);
- if (bo &&bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !before->bo_va->base.moved)amdgpu_vm_bo_moved(&before->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1957,7 +1955,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev, if (after->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !after->bo_va->base.moved)amdgpu_vm_bo_moved(&after->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2037,7 +2035,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, if (bo) { dma_resv_assert_held(bo->tbo.base.resv); - if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + if (amdgpu_vm_is_bo_always_valid(vm, bo)) ttm_bo_set_bulk_move(&bo->tbo, NULL); for (base = &bo_va->base.bo->vm_bo; *base;@@ -2131,7 +2129,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) { struct amdgpu_vm *vm = bo_base->vm; - if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (evicted && amdgpu_vm_is_bo_always_valid(vm, bo)) { amdgpu_vm_bo_evicted(bo_base); continue;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -2142,7 +2140,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, if (bo->tbo.type == ttm_bo_type_kernel) amdgpu_vm_bo_relocated(bo_base); - else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + else if (amdgpu_vm_is_bo_always_valid(vm, bo)) amdgpu_vm_bo_moved(bo_base);else
amdgpu_vm_bo_invalidated(bo_base);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -3006,3 +3004,16 @@ void amdgpu_vm_update_fault_cache(structamdgpu_device *adev, xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); }+/**
+ *amdgpu_vm_is_bo_always_valid- check if the BO is VM always valid
+ *
+ * @vm: VM to test against.
+ * @abo: BO to be tested.
+ *
+ * Returns true if the BO shares thedma_resvobject with the root PD and is
+ * always guaranteed to be valid inside the VM.
+ */
+boolamdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0+{ + return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv; +}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m); int amdgpu_vm_pt_map_tables(struct amdgpu_device *adev, struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo); + /*** amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query
Christian König
maintainerAm 16.05.24 um 14:21 schrieb Tvrtko Ursulin:
Quoted 76 lines
Hi Christian,
Quoted 72 lines · Tvrtko Ursulin
Quoted 71 lines · Christian König
Am 06.05.24 um 18:26 schrieb Tvrtko Ursulin:
Quoted 69 lines · Tvrtko Ursulin
Quoted 55 lines
From: Tvrtko Ursulin <[email protected]>
Help code readability by replacing a bunch of:
bo->tbo.base.resv==vm->root.bo->tbo.base.resvWith:
amdgpu_vm_is_bo_always_valid(vm, bo)No functional changes.
v2:
* Rename helper and move toamdgpu_vm. (Christian)v3:
* Use Christian's kerneldoc.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41
++++++++++++++++---------
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 ++3 files changed, 29 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -174,7 +174,7 @@ static int amdgpu_gem_object_open(structdrm_gem_object *obj, return -EPERM;if (
abo->flags&AMDGPU_GEM_CREATE_VM_ALWAYS_VALID&& -abo->tbo.base.resv!=vm->root.bo->tbo.base.resv) + !amdgpu_vm_is_bo_always_valid(vm, abo)) return-EPERM;
r =amdgpu_bo_reserve(abo, false);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -333,7 +333,7 @@ void amdgpu_vm_bo_base_init(structamdgpu_vm_bo_base *base, base->next = bo->vm_bo; bo->vm_bo = base; - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) + if (!amdgpu_vm_is_bo_always_valid(vm, bo)) return;dma_resv_assert_held (vm->root.bo->tbo.base.resv);@@ -1101,13 +1101,13 @@ static void amdgpu_vm_bo_get_memory(structamdgpu_bo_va *bo_va, * For now ignore BOs which are currently locked and potentiallydrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_bo_get_memory(struct · line 1109
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-3* changing their location. */ - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv && + if (!amdgpu_vm_is_bo_always_valid(vm, bo) && !dma_resv_trylock(bo->tbo.base.resv)) return; amdgpu_bo_get_memory(bo, stats); - if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv) - dma_resv_unlock(bo->tbo.base.resv); + if (amdgpu_vm_is_bo_always_valid(vm, bo))Beware the logic inversion here - luckily no one merged it yet! I will send a respin..
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Let me know when that is done, I was about to merge it.
First three patches in the series https://lore.kernel.org/amd-gfx/[email protected]/ if you can pull it from there or I should resend standalone?
Please double check it though. Sorry about that I am so used to pre-merge CI we have on the i915 preventing silly mistakes such as that one.
Small reminder on the above since you have been out - are you okay to pick up the first three patches from https://lore.kernel.org/amd-gfx/[email protected]/, if they still look okay to you? Or I should re-send them standalone?
Ah, thanks for the reminder. Totally forgotten that I wanted to push this. Just done so.
Regards,
Christian.
Quoted 115 lines
Regards,
Tvrtko
Quoted 110 lines
Quoted 110 lines
Quoted 108 lines
Quoted 108 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+dma_resv_unlock (bo->tbo.base.resv); } void amdgpu_vm_get_memory(struct amdgpu_vm *vm,@@ -1203,8 +1203,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, uncached = false; }- if (clear || (bo &&
bo->tbo.base.resv== -vm->root.bo->tbo.base.resv))
+ if (clear ||amdgpu_vm_is_bo_always_valid(vm, bo))last_update=&vm->last_update;
else
last_update=&bo_va->last_pt_update;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1246,7 +1245,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device*adev, struct amdgpu_bo_va *bo_va, * the evicted list so that it gets validated again on the * next command submission. */ - if (bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (amdgpu_vm_is_bo_always_valid(vm, bo)) { uint32_t mem_type = bo->tbo.resource->mem_type;if (!(bo->preferred_domains &
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1640,10 +1639,9 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, if (mapping->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&&
- !bo_va->base.moved) {
+ if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !bo_va->base.moved)amdgpu_vm_bo_moved(&bo_va->base);
- }
+
trace_amdgpu_vm_bo_map(bo_va, mapping);
}
@@ -1942,7 +1940,7 @@ int amdgpu_vm_bo_clear_mappings(structamdgpu_device*adev, if (before->flags&AMDGPU_PTE_PRT)
amdgpu_vm_prt_get(adev);
- if (bo &&bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !before->bo_va->base.moved)amdgpu_vm_bo_moved(&before->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1957,7 +1955,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev, if (after->flags & AMDGPU_PTE_PRT) amdgpu_vm_prt_get(adev);- if (bo &&
bo->tbo.base.resv==vm->root.bo->tbo.base.resv&& + if (amdgpu_vm_is_bo_always_valid(vm, bo)&& !after->bo_va->base.moved)amdgpu_vm_bo_moved(&after->bo_va->base);
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2037,7 +2035,7 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev, if (bo) { dma_resv_assert_held(bo->tbo.base.resv); - if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + if (amdgpu_vm_is_bo_always_valid(vm, bo)) ttm_bo_set_bulk_move(&bo->tbo, NULL); for (base = &bo_va->base.bo->vm_bo; *base;@@ -2131,7 +2129,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) { struct amdgpu_vm *vm = bo_base->vm; - if (evicted && bo->tbo.base.resv == vm->root.bo->tbo.base.resv) { + if (evicted && amdgpu_vm_is_bo_always_valid(vm, bo)) { amdgpu_vm_bo_evicted(bo_base); continue;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -2142,7 +2140,7 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, if (bo->tbo.type == ttm_bo_type_kernel) amdgpu_vm_bo_relocated(bo_base); - else if (bo->tbo.base.resv == vm->root.bo->tbo.base.resv) + else if (amdgpu_vm_is_bo_always_valid(vm, bo)) amdgpu_vm_bo_moved(bo_base);else
amdgpu_vm_bo_invalidated(bo_base);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -3006,3 +3004,16 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); }+/**
+ *amdgpu_vm_is_bo_always_valid- check if the BO is VM always valid
+ *
+ * @vm: VM to test against.
+ * @abo: BO to be tested.
+ *
+ * Returns true if the BO shares thedma_resvobject with the root PD and is
+ * always guaranteed to be valid inside the VM.
+ */
+boolamdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0+{ + return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv; +}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -561,6 +561,8 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m); int amdgpu_vm_pt_map_tables(struct amdgpu_device *adev, struct amdgpu_vm *vm); +bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo); + /*** amdgpu_vm_tlb_seq - return tlb flush sequence number * @vm: the amdgpu_vm structure to query