drm/amdkfd: don't add DOORBELL and MMIO BOs to validate list
Subsystems (3)
PATCH 1/1 drm/amdkfd: don't add DOORBELL and MMIO BOs to validate list
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9 -5
@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;
@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);
@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;
@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Signature · 1 line
2.25.1
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.
Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
Christian.
Quoted 52 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Quoted 7 lines · Christian König
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The kfd_bo_list is used to restore BOs after evictions.
Do you mean their page tabes could be changed? Thanks.
Quoted 51 lines
Christian.
Quoted 48 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 6 lines · Christian König
Quoted 5 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
Quoted 7 lines
Quoted 1 line
So this here might break horrible.
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Regards,
Christian.
Quoted 51 lines
Quoted 51 lines
Christian.
Quoted 47 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Quoted 8 lines · Christian König
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 7 lines · Christian König
Quoted 6 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
Quoted 8 lines
Quoted 6 lines
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Destroyed? You mean the contents of page table BOs are disappeared. If so, could other BOs be destroyed under memory pressure? Thanks!
Regards,
Lang
Quoted 58 lines
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Regards,
Christian.Quoted 51 lines
Quoted 51 lines
Christian.
Quoted 47 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Am 25.05.22 um 13:37 schrieb Lang Yu:
Quoted 9 lines · Christian König
Quoted 8 lines
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 7 lines · Christian König
Quoted 6 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Destroyed? You mean the contents of page table BOs are disappeared.
Currently we try to just free up the backing store of them, but the idea is to really get rid of the whole BO under memory pressure.
See page tables are managed in a hierarchy and their content can be fully restored from the metadata.
So except for the root PD all page tables in a VM can (in theory) be destroyed and re-created when they are not used.
Quoted 1 line
If so, could other BOs be destroyed under memory pressure? Thanks!
I don't think so, everything else is just referenced somewhere.
Regards,
Christian.
Quoted 60 lines
Regards,
LangQuoted 56 lines
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Regards,
Christian.Quoted 50 lines
Quoted 50 lines
Christian.
Quoted 47 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Quoted 25 lines · Christian König
Am 25.05.22 um 13:37 schrieb Lang Yu:
Quoted 9 lines · Christian König
Quoted 8 lines
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 7 lines · Christian König
Quoted 6 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Destroyed? You mean the contents of page table BOs are disappeared.
Currently we try to just free up the backing store of them, but the idea is to really get rid of the whole BO under memory pressure.
See page tables are managed in a hierarchy and their content can be fully restored from the metadata.
Quoted 6 lines
So except for the root PD all page tables in a VM can (in theory) be destroyed and re-created when they are not used.
Quoted 1 line
If so, could other BOs be destroyed under memory pressure? Thanks!
I don't think so, everything else is just referenced somewhere.
Thanks. I got it. Just curious how do we identify PT BOs when we want to destroy them under memory pressure? And does this happen in eviction process?
Regards,
Lang
Quoted 64 lines
Regards,
Christian.Quoted 60 lines
Regards,
LangQuoted 56 lines
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Regards,
Christian.Quoted 50 lines
Quoted 50 lines
Christian.
Quoted 47 lines
Signed-off-by Lang Yu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem,struct ttm_validate_buffer *entry = &mem->validate_list;struct amdgpu_bo *bo = mem->bo; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; +INIT_LIST_HEAD (&entry->head); entry->num_shared =1 ; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, {struct ttm_validate_buffer *bo_list_entry; +if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) +return ; + bo_list_entry = &mem->validate_list;mutex_lock (&process_info->lock);list_del (&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(unsigned long bo_size = mem->bo->tbo.base.size;struct kfd_mem_attachment *entry, *tmp;struct bo_vm_reservation_context ctx; -struct ttm_validate_buffer *bo_list_entry;unsigned int mapped_to_gpu_memory;int ret;bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( }/* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; -mutex_lock (&process_info->lock); -list_del (&bo_list_entry->head); -mutex_unlock (&process_info->lock); +remove_kgd_mem_from_kfd_bo_list (mem, process_info);/* No more MMU notifiers */ amdgpu_mn_unregister (mem->bo);
Felix Kuehling
maintainerQuoted 8 lines · Christian König
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 7 lines · Christian König
Quoted 6 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
Quoted 8 lines
Quoted 6 lines
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Is that actually happening today, or is that some future optimization you have in mind? I know page tables can get evicted, but I didn't think they were destroyed unless the memory at that address is unmapped (which never happens for pinned BOs).
Quoted 2 lines
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Then we already have some other broken cases for the small number of kmapped BOs that are pinned and currently removed from the validation list (see amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel).
Regards,
Felix
Quoted 59 lines
Regards,
Christian.Quoted 54 lines
Quoted 54 lines
Christian.
Quoted 50 lines
Signed-off-by Lang Yu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 14
+++++++++-----1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem, struct ttm_validate_buffer *entry = &mem->validate_list; struct amdgpu_bo *bo = mem->bo; + if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | + KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) + return; + INIT_LIST_HEAD(&entry->head); entry->num_shared = 1; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, { struct ttm_validate_buffer *bo_list_entry; + if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | + KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) + return; + bo_list_entry = &mem->validate_list; mutex_lock(&process_info->lock); list_del(&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( unsigned long bo_size = mem->bo->tbo.base.size; struct kfd_mem_attachment *entry, *tmp; struct bo_vm_reservation_context ctx; - struct ttm_validate_buffer *bo_list_entry; unsigned int mapped_to_gpu_memory; int ret; bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( } /* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; - mutex_lock(&process_info->lock); - list_del(&bo_list_entry->head); - mutex_unlock(&process_info->lock); + remove_kgd_mem_from_kfd_bo_list(mem, process_info); /* No more MMU notifiers */ amdgpu_mn_unregister(mem->bo);
Am 26.05.22 um 00:17 schrieb Felix Kuehling:
Quoted 13 lines · Christian König
Quoted 11 lines
Am 25.05.22 um 11:25 schrieb Lang Yu:
Quoted 10 lines · Christian König
Quoted 6 lines
Am 25.05.22 um 10:43 schrieb Lang Yu:
Quoted 2 lines
DOORBELL and MMIO BOs never move once created.
No need to validate them after that.Yeah, but you still need to make sure their page tables are up to date.
So this here might break horrible.
These BOs(and attachments) are validated when allocated and mapped. Their page tables should be determined at this time.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
The
kfd_bo_listis used to restore BOs after evictions.Do you mean their page tabes could be changed? Thanks.
Yes, page tables can be destroyed under memory pressure as well.
Is that actually happening today, or is that some future optimization you have in mind? I know page tables can get evicted, but I didn't think they were destroyed unless the memory at that address is unmapped (which never happens for pinned BOs).
We partially already do that, but it is largely for future optimizations.
Currently page tables are moved to system memory and occupy system pages. But that's just utterly nonsense because they are re-created anyway when they move back in.
Quoted 4 lines
Quoted 2 lines
Not sure how the KFD handles that, but in theory we should have every BO used by a process on the validation list. Even the ones pinned.
Then we already have some other broken cases for the small number of kmapped BOs that are pinned and currently removed from the validation list (see
amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel).
That's indeed broken then and only works by coincidence (the pinned and unpinned probably BOs don't overlap an evicted page table).
Regards,
Christian.
Quoted 64 lines
Regards,
FelixQuoted 59 lines
Regards,
Christian.Quoted 54 lines
Quoted 54 lines
Christian.
Quoted 50 lines
Signed-off-by Lang Yu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 14
+++++++++-----1 file changed, 9 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9
-5@@ -808,6 +808,10 @@ static void add_kgd_mem_to_kfd_bo_list(struct kgd_mem *mem, struct ttm_validate_buffer *entry = &mem->validate_list; struct amdgpu_bo *bo = mem->bo; + if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | + KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) + return; + INIT_LIST_HEAD(&entry->head); entry->num_shared = 1; entry->bo = &bo->tbo;@@ -824,6 +828,10 @@ static void remove_kgd_mem_from_kfd_bo_list(struct kgd_mem *mem, { struct ttm_validate_buffer *bo_list_entry; + if (mem->alloc_flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | + KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) + return; + bo_list_entry = &mem->validate_list; mutex_lock(&process_info->lock); list_del(&bo_list_entry->head);@@ -1649,7 +1657,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( unsigned long bo_size = mem->bo->tbo.base.size; struct kfd_mem_attachment *entry, *tmp; struct bo_vm_reservation_context ctx; - struct ttm_validate_buffer *bo_list_entry; unsigned int mapped_to_gpu_memory; int ret; bool is_imported = false;@@ -1677,10 +1684,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( } /* Make sure restore workers don't access the BO any more */ - bo_list_entry = &mem->validate_list; - mutex_lock(&process_info->lock); - list_del(&bo_list_entry->head); - mutex_unlock(&process_info->lock); + remove_kgd_mem_from_kfd_bo_list(mem, process_info); /* No more MMU notifiers */ amdgpu_mn_unregister(mem->bo);