drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
Subsystems (3)
PATCH 1/1 drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +25 -0
@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config);void amdgpu_amdkfd_ras_poison_consumption_handler (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.31.1
Felix Kuehling
maintainerAm 2021-11-08 um 8:37 p.m. schrieb Ramesh Errabolu:
Quoted 2 lines
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
The PCIe connected peer device access isn't an issue on the upstream branch (yet). But in general, it is a good idea to pin these SG BOs. There is no good reason to have them on the TTM LRU list. And they do reference fixed physical addresses.
See one more comment inline.
Quoted 30 lines
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +15
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); +
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, · line 327
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +10
-0+/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +
These declarations aren't needed here. The functions should be static because they are only used in the same source file.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, · line 1302
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config);void amdgpu_amdkfd_ras_poison_consumption_handler (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain)
static
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8
-0+{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 );
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, · line 1320
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10
-0+if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo)
static
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11
-0+{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1563
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow;
Actually, I think this is wrong. You need a new label before drm_vma_node_revoke to make sure the entry in the node permission structure is not leaked.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1569
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-0+ } + + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow;
Same as above.
Regards,
Felix
Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +13
-0+ } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock);
[AMD Official Use Only]
Responses in line
Regards,
Ramesh
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Monday, November 8, 2021 10:51 PM
To: [email protected]; Errabolu, Ramesh <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
Am 2021-11-08 um 8:37 p.m. schrieb Ramesh Errabolu:
Quoted 2 lines
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
The PCIe connected peer device access isn't an issue on the upstream branch (yet). But in general, it is a good idea to pin these SG BOs. There is no good reason to have them on the TTM LRU list. And they do reference fixed physical addresses.
See one more comment inline.
Quoted 33 lines
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +16
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/**
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, · line 328
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +10
-0+* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following +criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +
These declarations aren't needed here. The functions should be static because they are only used in the same source file.
Ramesh: Removed them from the header file
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config); void amdgpu_amdkfd_ras_poison_consumption_handler(struct
amdgpu_device*adev); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cindex4fa814358552..f4ffc41873dd100644
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, · line 1302
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain)
Static
Ramesh: Updated function signature to make it static
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8
-0+{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 );
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, · line 1320
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10
-0+if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo)
static
Ramesh: Same as above
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11
-0+{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1563
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow;
Actually, I think this is wrong. You need a new label before drm_vma_node_revoke to make sure the entry in the node permission structure is not leaked.
Ramesh: Good catch - using a new label - "err_pin_bo"
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1569
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-0+ } + + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow;
Same as above.
Regards,
Felix
Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +13
-0+ } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock);
Quoted 87 lines · Ramesh Errabolu
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +25
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config);void amdgpu_amdkfd_ras_poison_consumption_handler (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +30
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain) +{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 ); +if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo) +{ +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1564
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + }
amdgpu_amdkfd_gpuvm_pin_bo() will do ttm_bo_validate(), amdgpu_amdkfd_bo_validate() seems redundant here.
Regards,
Lang
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +18
-0+ + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock);Signature · 1 line
2.31.1
[AMD Official Use Only]
Responses in line
-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Monday, November 8, 2021 11:27 PM
To: Errabolu, Ramesh <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
Quoted 90 lines · Ramesh Errabolu
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +26
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following +criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config); void amdgpu_amdkfd_ras_poison_consumption_handler(struct
amdgpu_device*adev); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cindex4fa814358552..f4ffc41873dd100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +28
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 ); +if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1564
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + }
amdgpu_amdkfd_gpuvm_pin_bo() will do ttm_bo_validate(), amdgpu_amdkfd_bo_validate() seems redundant here.
Ramesh: In my experiments I recall seeing an issue if BO was not validated in GTT domain prior to pinning. If my memory serves me correctly, the call to PIN will fail
Regards,
Lang
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +18
-1+ + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock); --2.31.1
Quoted 116 lines · Ramesh
[AMD Official Use Only]
Responses in line
-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Monday, November 8, 2021 11:27 PM
To: Errabolu, Ramesh <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domainQuoted 90 lines · Ramesh Errabolu
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +26
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following +criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config); void amdgpu_amdkfd_ras_poison_consumption_handler(struct
amdgpu_device*adev); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cindex4fa814358552..f4ffc41873dd100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +28
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 ); +if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1564
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + }
amdgpu_amdkfd_gpuvm_pin_bo()will dottm_bo_validate(),amdgpu_amdkfd_bo_validate()seems redundant here.
Quoted 1 line
Ramesh: In my experiments I recall seeing an issue if BO was not validated in GTT domain prior to pinning. If my memory serves me correctly, the call to PIN will fail
From amdgpu_bo_pin_restricted() we can see, pin operation will
If not pinned,
1, validate the BO with requested domain
2, increase pin count and update stats
If already pinned,
1, increase pin count
So seems not necessarily to validate it twice.
Regards,
Lang
Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +18
-1+ + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock); --2.31.1
[AMD Official Use Only]
I will experiment to see if it is not needed. Will update patch based on the results.
Regards,
Ramesh
________________________________
From: Yu, Lang <[email protected]>
Sent: Tuesday, November 9, 2021 12:44 AM
To: Errabolu, Ramesh <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
Quoted 116 lines · Ramesh
[AMD Official Use Only]
Responses in line
-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Monday, November 8, 2021 11:27 PM
To: Errabolu, Ramesh <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domainQuoted 90 lines · Ramesh Errabolu
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
Signed-off-by Ramesh Errabolu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +26
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following +criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config); void amdgpu_amdkfd_ras_poison_consumption_handler(struct
amdgpu_device*adev); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cindex4fa814358552..f4ffc41873dd100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +28
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 ); +if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1564
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + }
amdgpu_amdkfd_gpuvm_pin_bo()will dottm_bo_validate(),amdgpu_amdkfd_bo_validate()seems redundant here.
Quoted 1 line
Ramesh: In my experiments I recall seeing an issue if BO was not validated in GTT domain prior to pinning. If my memory serves me correctly, the call to PIN will fail
From amdgpu_bo_pin_restricted() we can see, pin operation will
If not pinned,
1, validate the BO with requested domain 2, increase pin count and update stats
If already pinned,
1, increase pin count
So seems not necessarily to validate it twice.
Regards,
Lang
Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +18
-1+ + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock); --2.31.1
[AMD Official Use Only]
Based on my experiments I am able conclude that I can avoid validating the BO prior to pinning it. I don't have the code history that led me to validating the BO in the first place. In any case I posted an updated patch to the DRM-NEXT branch in addition to a standalone patch for the DKMS branch as well.
Thanks for pointing this out.
Regards,
Ramesh
From: Errabolu, Ramesh <[email protected]>
Sent: Tuesday, November 9, 2021 1:32 AM
To: Yu, Lang <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
I will experiment to see if it is not needed. Will update patch based on the results.
Regards,
Ramesh
________________________________
From: Yu, Lang <[email protected]<mailto:[email protected]>>
Sent: Tuesday, November 9, 2021 12:44 AM
To: Errabolu, Ramesh <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domain
Quoted 116 lines · Ramesh
[AMD Official Use Only]
Responses in line
-----Original Message-----
From: Yu, Lang <[email protected]<mailto:[email protected]>>
Sent: Monday, November 8, 2021 11:27 PM
To: Errabolu, Ramesh <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Pin MMIO/DOORBELL BO's in GTT domainQuoted 90 lines · Ramesh Errabolu
MMIO/DOORBELL BOs encode control data and should be pinned in GTT domain before enabling PCIe connected peer devices in accessing it
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 25 +++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 55 +++++++++++++++++++ 2 files changed, 80 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +26
-0@@ -300,6 +300,31 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev, uint64_t va, void *drm_priv, struct kgd_mem **mem, uint64_t *size, uint64_t *mmap_offset); + +/** +* amdgpu_amdkfd_gpuvm_pin_bo() - Pins a BO using following criteria +* @bo: Handle of buffer object being pinned +* @domain: Domain into which BO should be pinned +* +* - USERPTR BOs are UNPINNABLE and will return error +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count incremented. It is valid to PIN a BO multiple times +* +* Return: ZERO if successful in pinning, Non-Zero in case of error. +* Will return -EINVAL if input BO parameter is a USERPTR type. +*/ +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain); + +/** +* amdgpu_amdkfd_gpuvm_unpin_bo() - Unpins BO using following +criteria +* @bo: Handle of buffer object being unpinned +* +* - Is a illegal request for USERPTR BOs and is ignored +* - All other BO types (GTT, VRAM, MMIO and DOORBELL) will have their +* PIN count decremented. Calls to UNPIN must balance calls to PIN +*/ +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo); +int amdgpu_amdkfd_get_tile_config (struct amdgpu_device *adev,struct tile_config *config); void amdgpu_amdkfd_ras_poison_consumption_handler(struct
amdgpu_device*adev); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.cindex4fa814358552..f4ffc41873dd100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +28
-0@@ -1299,6 +1299,36 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,return ret; } +int amdgpu_amdkfd_gpuvm_pin_bo (struct amdgpu_bo *bo,u32 domain) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ret; + + ret =amdgpu_bo_pin_restricted (bo, domain,0 ,0 ); +if (ret) +pr_err ("Error in Pinning BO to domain: %d\n" , domain); + +amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); +amdgpu_bo_unreserve (bo); + +return ret; +} + +void amdgpu_amdkfd_gpuvm_unpin_bo (struct amdgpu_bo *bo) { +int ret =0 ; + + ret =amdgpu_bo_reserve (bo, false); +if (unlikely (ret)) +return ; + +amdgpu_bo_unpin (bo); +amdgpu_bo_unreserve (bo); +} + int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev, struct file *filp, u32 pasid, void **process_info,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( · line 1564
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7
-0@@ -1525,6 +1555,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (offset) *offset =amdgpu_bo_mmap_offset (bo); +if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (ret) { +pr_err ("Validating MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + }
amdgpu_amdkfd_gpuvm_pin_bo()will dottm_bo_validate(),amdgpu_amdkfd_bo_validate()seems redundant here.
Quoted 1 line
Ramesh: In my experiments I recall seeing an issue if BO was not validated in GTT domain prior to pinning. If my memory serves me correctly, the call to PIN will fail
From amdgpu_bo_pin_restricted() we can see, pin operation will
If not pinned,
1, validate the BO with requested domain
2, increase pin count and update stats
If already pinned,
1, increase pin count
So seems not necessarily to validate it twice.
Regards,
Lang
Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +18
-1+ + ret =amdgpu_amdkfd_gpuvm_pin_bo (bo,AMDGPU_GEM_DOMAIN_GTT ); +if (ret) { +pr_err ("Pinning MMIO/DOORBELL BO during ALLOC FAILED\n" ); + goto err_node_allow; + } + bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; + bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ; + } +return 0 ; allocate_init_user_pages_failed:@@ -1561,6 +1608,14 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(bool is_imported = false;mutex_lock (&mem->lock); + +/* Unpin MMIO/DOORBELL BO's that were pinnned during allocation */ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock); --2.31.1