Best effort contiguous VRAM allocation
Subsystems (3)
v3 cover Best effort contiguous VRAM allocation
This patch series implement new KFD memory alloc flag for best effort contiguous VRAM allocation, to support peer direct access RDMA device with limited scatter-gather dma capability.
v2: rebase on patch ("drm/amdgpu: Modify the contiguous flags behaviour")
to avoid adding the new GEM flag
v3: add patch 2 to handle sg segment size limit (Christian)
Philip Yang (7):
drm/amdgpu: Support contiguous VRAM allocation drm/amdgpu: Handle sg size limit for contiguous allocation drm/amdgpu: Evict BOs from same process for contiguous allocation drm/amdkfd: Evict BO itself for contiguous allocation drm/amdkfd: Increase KFD bo restore wait time drm/amdgpu: Skip dma map resource for null RDMA device drm/amdkfd: Bump kfd version for contiguous VRAM allocation
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 20 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 50 ++++++++++++------- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- include/uapi/linux/kfd_ioctl.h | 4 +- 5 files changed, 56 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.2
PATCH v3 1/7 drm/amdgpu: Support contiguous VRAM allocation
RDMA device with limited scatter-gather ability requires contiguous VRAM buffer allocation for RDMA peer direct support.
Add a new KFD alloc memory flag and store as bo alloc flag AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS. When pin this bo to export for RDMA peerdirect access, this will set TTM_PL_FLAG_CONTIFUOUS flag, and ask VRAM buddy allocator to get contiguous VRAM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 ++++ include/uapi/linux/kfd_ioctl.h | 1 + 2 files changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -0
@@ -1712,6 +1712,10 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( alloc_flags =AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE ; alloc_flags |= (flags &KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC ) ?AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED :0 ; + +/* For contiguous VRAM allocation */ +if (flags &KFD_IOC_ALLOC_MEM_FLAGS_CONTIGUOUS_BEST_EFFORT ) + alloc_flags |=AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS ; } xcp_id = fpriv->xcp_id ==AMDGPU_XCP_NO_PARTITION ?0 : fpriv->xcp_id;
include/uapi/linux/kfd_ioctl.h +1 -0
@@ -407,6 +407,7 @@ struct kfd_ioctl_acquire_vm_args {#define KFD_IOC_ALLOC_MEM_FLAGS_COHERENT (1 << 26)#define KFD_IOC_ALLOC_MEM_FLAGS_UNCACHED (1 << 25)#define KFD_IOC_ALLOC_MEM_FLAGS_EXT_COHERENT (1 << 24) +#define KFD_IOC_ALLOC_MEM_FLAGS_CONTIGUOUS_BEST_EFFORT (1 << 23)/* Allocate memory for later SVM (shared virtual memory) mapping. *
Signature · 1 line
2.43.2
PATCH v3 2/7 drm/amdgpu: Handle sg size limit for contiguous allocation
In reply to Philip YangDefine macro MAX_SG_SEGMENT_SIZE 2GB, because struct scatterlist length is unsigned int, and some users of it cast to a signed int, so every segment of sg table is limited to size 2GB maximum.
For contiguous VRAM allocation, don't limit the max buddy block size in order to get contiguous VRAM memory. To workaround the sg table segment size limit, allocate multiple segments if contiguous size is bigger than MAX_SG_SEGMENT_SIZE.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +12 -5
@@ -31,6 +31,8 @@#include "amdgpu_atomfirmware.h" #include "atom.h" +#define MAX_SG_SEGMENT_SIZE (2UL << 30) +struct amdgpu_vram_reservation {u64 start;u64 size;
@@ -532,8 +534,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,BUG_ON (min_block_size < mm->chunk_size); -/* Limit maximum size to 2GiB due to SG table limitations */ - size =min (remaining_size,2ULL <<30 ); +if (place->flags &TTM_PL_FLAG_CONTIGUOUS ) + size = remaining_size; +else +/* Limit maximum size to 2GiB due to SG table limitations +* for no contiguous allocation. +*/ + size =min (remaining_size,MAX_SG_SEGMENT_SIZE );if ((size >= (u64 )pages_per_block <<PAGE_SHIFT ) && !(size & (((u64 )pages_per_block <<PAGE_SHIFT ) -1 )))
@@ -675,7 +682,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,amdgpu_res_first (res, offset, length, &cursor);while (cursor.remaining) { num_entries++; -amdgpu_res_next (&cursor, cursor.size); +amdgpu_res_next (&cursor,min (cursor.size,MAX_SG_SEGMENT_SIZE )); } r =sg_alloc_table (*sgt, num_entries,GFP_KERNEL );
@@ -695,7 +702,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,amdgpu_res_first (res, offset, length, &cursor);for_each_sgtable_sg ((*sgt), sg, i) {phys_addr_t phys = cursor.start + adev->gmc.aper_base; -size_t size = cursor.size; +unsigned long size =min (cursor.size,MAX_SG_SEGMENT_SIZE );dma_addr_t addr; addr = dma_map_resource(dev, phys, size, dir,
@@ -708,7 +715,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,sg_dma_address (sg) = addr;sg_dma_len (sg) = size; -amdgpu_res_next (&cursor, cursor.size); +amdgpu_res_next (&cursor, size); }return 0 ;
Signature · 1 line
2.43.2
Christian König
maintainerRe: [PATCH v3 2/7] drm/amdgpu: Handle sg size limit for contiguous allocation
Am 22.04.24 um 15:57 schrieb Philip Yang:
Quoted 30 lines
Define macro
MAX_SG_SEGMENT_SIZE2GB, because struct scatterlist length is unsigned int, and some users of it cast to a signed int, so every segment of sg table is limited to size 2GB maximum.For contiguous VRAM allocation, don't limit the max buddy block size in order to get contiguous VRAM memory. To workaround the sg table segment size limit, allocate multiple segments if contiguous size is bigger than
MAX_SG_SEGMENT_SIZE.Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +2
-0@@ -31,6 +31,8 @@#include "amdgpu_atomfirmware.h" #include "atom.h" +#define MAX_SG_SEGMENT_SIZE (2UL << 30) +struct amdgpu_vram_reservation {u64 start;u64 size;@@ -532,8 +534,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,BUG_ON (min_block_size < mm->chunk_size);
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 543
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7
-2-/* Limit maximum size to 2GiB due to SG table limitations */ - size =min (remaining_size,2ULL <<30 ); +if (place->flags &TTM_PL_FLAG_CONTIGUOUS ) + size = remaining_size; +else +/* Limit maximum size to 2GiB due to SG table limitations +* for no contiguous allocation. +*/ + size =min (remaining_size,MAX_SG_SEGMENT_SIZE );
Well that doesn't make sense, either fix the creation of the sg tables or limit the segment size. Not both.
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1if ((size >= (u64 )pages_per_block <<PAGE_SHIFT ) && !(size & (((u64 )pages_per_block <<PAGE_SHIFT ) -1 )))@@ -675,7 +682,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,amdgpu_res_first (res, offset, length, &cursor);while (cursor.remaining) { num_entries++; -amdgpu_res_next (&cursor, cursor.size); +amdgpu_res_next (&cursor,min (cursor.size,MAX_SG_SEGMENT_SIZE )); } r =sg_alloc_table (*sgt, num_entries,GFP_KERNEL );
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev, · line 705
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1@@ -695,7 +702,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,amdgpu_res_first (res, offset, length, &cursor);for_each_sgtable_sg ((*sgt), sg, i) {phys_addr_t phys = cursor.start + adev->gmc.aper_base; -size_t size = cursor.size; +unsigned long size =min (cursor.size,MAX_SG_SEGMENT_SIZE );
Please keep size_t here or use unsigned int, using unsigned long just looks like trying to hide the problem.
And I wouldn't use a separate define but rather just INT_MAX instead.
Regards,
Christian.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1dma_addr_t addr; addr = dma_map_resource(dev, phys, size, dir,@@ -708,7 +715,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,sg_dma_address (sg) = addr;sg_dma_len (sg) = size; -amdgpu_res_next (&cursor, cursor.size); +amdgpu_res_next (&cursor, size); }return 0 ;
Re: [PATCH v3 2/7] drm/amdgpu: Handle sg size limit for contiguous allocation
On 2024-04-22 10:40, Christian König wrote:
Am 22.04.24 um 15:57 schrieb Philip Yang:
Define macro MAX_SG_SEGMENT_SIZE 2GB, because struct scatterlist length is unsigned int, and some users of it cast to a signed int, so every segment of sg table is limited to size 2GB maximum.
For contiguous VRAM allocation, don't limit the max buddy block size in order to get contiguous VRAM memory. To workaround the sg table segment size limit, allocate multiple segments if contiguous size is bigger than MAX_SG_SEGMENT_SIZE.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0 -0
@@ -31,6 +31,8 @@
#include "amdgpu_atomfirmware.h"
#include "atom.h"
+#define MAX_SG_SEGMENT_SIZE (2UL << 30)
+
struct amdgpu_vram_reservation {
u64 start;
u64 size;
@@ -532,8 +534,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, BUG_ON(min_block_size < mm->chunk_size);
- /* Limit maximum size to 2GiB due to SG table limitations */ - size = min(remaining_size, 2ULL << 30);
+ if (place->flags & TTM_PL_FLAG_CONTIGUOUS)
+ size = remaining_size;
+ else
+ /* Limit maximum size to 2GiB due to SG table limitations + * for no contiguous allocation.
+ */
+ size = min(remaining_size, MAX_SG_SEGMENT_SIZE);
Well that doesn't make sense, either fix the creation of the sg tables or limit the segment size. Not both.
yes, right. we don't need limit the segment size for non-contiguous allocation either as this is handled by min_block_size. I will send v4 patch to fix this. Then we could have another patch to remove the while loop, size and remaining size to simply the code in future.
Regards,
Philip
if ((size >= (u64)pages_per_block << PAGE_SHIFT) && !(size & (((u64)pages_per_block << PAGE_SHIFT) - 1))) @@ -675,7 +682,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev, amdgpu_res_first(res, offset, length, &cursor);
while (cursor.remaining) {
num_entries++;
- amdgpu_res_next(&cursor, cursor.size);
+ amdgpu_res_next(&cursor, min(cursor.size, MAX_SG_SEGMENT_SIZE)); }
r = sg_alloc_table(*sgt, num_entries, GFP_KERNEL);
@@ -695,7 +702,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev, amdgpu_res_first(res, offset, length, &cursor); for_each_sgtable_sg((*sgt), sg, i) {
phys_addr_t phys = cursor.start + adev->gmc.aper_base; - size_t size = cursor.size;
+ unsigned long size = min(cursor.size, MAX_SG_SEGMENT_SIZE);
Please keep size_t here or use unsigned int, using unsigned long just looks like trying to hide the problem.
And I wouldn't use a separate define but rather just INT_MAX instead.
Regards,
Christian.
dma_addr_t addr;
addr = dma_map_resource(dev, phys, size, dir,
@@ -708,7 +715,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev, sg_dma_address(sg) = addr;
sg_dma_len(sg) = size;
- amdgpu_res_next(&cursor, cursor.size);
+ amdgpu_res_next(&cursor, size);
}
return 0;
PATCH v3 3/7 drm/amdgpu: Evict BOs from same process for contiguous allocation
In reply to Philip YangWhen TTM failed to alloc VRAM, TTM try evict BOs from VRAM to system memory then retry the allocation, this skips the KFD BOs from the same process because KFD require all BOs are resident for user queues.
If TTM with TTM_PL_FLAG_CONTIGUOUS flag to alloc contiguous VRAM, allow TTM evict KFD BOs from the same process, this will evict the user queues first, and restore the queues later after contiguous VRAM allocation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
@@ -1398,7 +1398,8 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,*/ dma_resv_for_each_fence (&resv_cursor, bo->base.resv,DMA_RESV_USAGE_BOOKKEEP , f) { -if (amdkfd_fence_check_mm (f, current->mm)) +if (amdkfd_fence_check_mm (f, current->mm) && + !(place->flags &TTM_PL_FLAG_CONTIGUOUS ))return false; }
Signature · 1 line
2.43.2
PATCH v3 4/7 drm/amdkfd: Evict BO itself for contiguous allocation
In reply to Philip YangIf the BO pages pinned for RDMA is not contiguous on VRAM, evict it to system memory first to free the VRAM space, then allocate contiguous VRAM space, and then move it from system memory back to VRAM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +15 -1
@@ -1470,13 +1470,27 @@ static int amdgpu_amdkfd_gpuvm_pin_bo(struct amdgpu_bo *bo, u32 domain)if (unlikely (ret))return ret; +if (bo->flags &AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS ) { +/* +* If bo is not contiguous on VRAM, move to system memory first to ensure +* we can get contiguous VRAM space after evicting other BOs. +*/ +if (!(bo->tbo.resource->placement &TTM_PL_FLAG_CONTIGUOUS )) { + ret =amdgpu_amdkfd_bo_validate (bo,AMDGPU_GEM_DOMAIN_GTT , false); +if (unlikely (ret)) { +pr_debug ("validate bo 0x%p to GTT failed %d\n" , &bo->tbo, ret); + goto out; + } + } + } + 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); +out:amdgpu_bo_unreserve (bo); -return ret; }
Signature · 1 line
2.43.2
PATCH v3 5/7 drm/amdkfd: Increase KFD bo restore wait time
In reply to Philip YangTTM allocate contiguous VRAM may takes more than 1 second to evict BOs for larger size RDMA buffer. Because KFD restore bo worker reserves all KFD BOs, then TTM cannot hold the remainning KFD BOs lock to evict them, this causes TTM failed to alloc contiguous VRAM.
Increase the KFD restore BO wait time to 2 seconds, long enough for RDMA pin BO to alloc the contiguous VRAM.
--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
@@ -698,7 +698,7 @@ struct qcm_process_device {/* KFD Memory Eviction */ /* Approx. wait time before attempting to restore evicted BOs */ -#define PROCESS_RESTORE_TIME_MS 100 +#define PROCESS_RESTORE_TIME_MS 2000/* Approx. back off time if restore fails due to lack of memory */ #define PROCESS_BACK_OFF_TIME_MS 100/* Approx. time before evicting the process again */
Signature · 1 line
2.43.2
PATCH v3 6/7 drm/amdgpu: Skip dma map resource for null RDMA device
In reply to Philip YangTo test RDMA using dummy driver on the system without NIC/RDMA device, the get/put dma pages pass in null device pointer, skip the dma map/unmap resource and sg table to avoid null pointer access.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33 +++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19 -14
@@ -705,12 +705,15 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,unsigned long size =min (cursor.size,MAX_SG_SEGMENT_SIZE );dma_addr_t addr; - addr =dma_map_resource (dev, phys, size, dir, -DMA_ATTR_SKIP_CPU_SYNC ); - r =dma_mapping_error (dev, addr); -if (r) - goto error_unmap; - +if (dev) { + addr =dma_map_resource (dev, phys, size, dir, +DMA_ATTR_SKIP_CPU_SYNC ); + r =dma_mapping_error (dev, addr); +if (r) + goto error_unmap; + }else { + addr = phys; + }sg_set_page (sg,NULL , size,0 );sg_dma_address (sg) = addr;sg_dma_len (sg) = size;
@@ -724,10 +727,10 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,for_each_sgtable_sg ((*sgt), sg, i) {if (!sg->length)continue ; - -dma_unmap_resource (dev, sg->dma_address, - sg->length, dir, -DMA_ATTR_SKIP_CPU_SYNC ); +if (dev) +dma_unmap_resource (dev, sg->dma_address, + sg->length, dir, +DMA_ATTR_SKIP_CPU_SYNC ); }sg_free_table (*sgt);
@@ -752,10 +755,12 @@ void amdgpu_vram_mgr_free_sgt(struct device *dev,struct scatterlist *sg;int i; -for_each_sgtable_sg (sgt, sg, i) -dma_unmap_resource (dev, sg->dma_address, - sg->length, dir, -DMA_ATTR_SKIP_CPU_SYNC ); +if (dev) { +for_each_sgtable_sg (sgt, sg, i) +dma_unmap_resource (dev, sg->dma_address, + sg->length, dir, +DMA_ATTR_SKIP_CPU_SYNC ); + }sg_free_table (sgt);kfree (sgt); }
Signature · 1 line
2.43.2
Christian König
maintainerRe: [PATCH v3 6/7] drm/amdgpu: Skip dma map resource for null RDMA device
Am 22.04.24 um 15:57 schrieb Philip Yang:
Quoted 3 lines
To test RDMA using dummy driver on the system without NIC/RDMA device, the get/put dma pages pass in null device pointer, skip the dma map/unmap resource and sg table to avoid null pointer access.
Well that is completely illegal and would break IOMMU.
Why does the RDMA driver does that in the first place?
Regards,
Christian.
Quoted 64 lines
Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33 +++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-14@@ -705,12 +705,15 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,unsigned long size =min (cursor.size,MAX_SG_SEGMENT_SIZE );dma_addr_t addr; - addr =dma_map_resource (dev, phys, size, dir, -DMA_ATTR_SKIP_CPU_SYNC ); - r =dma_mapping_error (dev, addr); -if (r) - goto error_unmap; - +if (dev) { + addr =dma_map_resource (dev, phys, size, dir, +DMA_ATTR_SKIP_CPU_SYNC ); + r =dma_mapping_error (dev, addr); +if (r) + goto error_unmap; + }else { + addr = phys; + }sg_set_page (sg,NULL , size,0 );sg_dma_address (sg) = addr;sg_dma_len (sg) = size;@@ -724,10 +727,10 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,for_each_sgtable_sg ((*sgt), sg, i) {if (!sg->length)continue ; - -dma_unmap_resource (dev, sg->dma_address, - sg->length, dir, -DMA_ATTR_SKIP_CPU_SYNC ); +if (dev) +dma_unmap_resource (dev, sg->dma_address, + sg->length, dir, +DMA_ATTR_SKIP_CPU_SYNC ); }sg_free_table (*sgt);@@ -752,10 +755,12 @@ void amdgpu_vram_mgr_free_sgt(struct device *dev,struct scatterlist *sg;int i; -for_each_sgtable_sg (sgt, sg, i) -dma_unmap_resource (dev, sg->dma_address, - sg->length, dir, -DMA_ATTR_SKIP_CPU_SYNC ); +if (dev) { +for_each_sgtable_sg (sgt, sg, i) +dma_unmap_resource (dev, sg->dma_address, + sg->length, dir, +DMA_ATTR_SKIP_CPU_SYNC ); + }sg_free_table (sgt);kfree (sgt); }
Re: [PATCH v3 6/7] drm/amdgpu: Skip dma map resource for null RDMA device
On 2024-04-22 10:56, Christian König wrote:
Am 22.04.24 um 15:57 schrieb Philip Yang:
To test RDMA using dummy driver on the system without NIC/RDMA device, the get/put dma pages pass in null device pointer, skip the dma map/unmap resource and sg table to avoid null pointer access.
Well that is completely illegal and would break IOMMU.
Why does the RDMA driver does that in the first place?
That is the amdp2ptest driver, part of KFDTest rdma test. The simple rdma test app and driver is used to test the driver path, without actually transferring data b/w machines.
Regards,
Philip
Regards,
Christian.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33 +++++++++++---------
1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0 -0
@@ -705,12 +705,15 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,
unsigned long size = min(cursor.size, MAX_SG_SEGMENT_SIZE); dma_addr_t addr;
- addr = dma_map_resource(dev, phys, size, dir,
- DMA_ATTR_SKIP_CPU_SYNC);
- r = dma_mapping_error(dev, addr);
- if (r)
- goto error_unmap;
-
+ if (dev) {
+ addr = dma_map_resource(dev, phys, size, dir,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ r = dma_mapping_error(dev, addr);
+ if (r)
+ goto error_unmap;
+ } else {
+ addr = phys;
+ }
sg_set_page(sg, NULL, size, 0);
sg_dma_address(sg) = addr;
sg_dma_len(sg) = size;
@@ -724,10 +727,10 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev, for_each_sgtable_sg((*sgt), sg, i) {
if (!sg->length)
continue;
-
- dma_unmap_resource(dev, sg->dma_address,
- sg->length, dir,
- DMA_ATTR_SKIP_CPU_SYNC);
+ if (dev)
+ dma_unmap_resource(dev, sg->dma_address,
+ sg->length, dir,
+ DMA_ATTR_SKIP_CPU_SYNC);
}
sg_free_table(*sgt);
@@ -752,10 +755,12 @@ void amdgpu_vram_mgr_free_sgt(struct device *dev, struct scatterlist *sg;
int i;
- for_each_sgtable_sg(sgt, sg, i)
- dma_unmap_resource(dev, sg->dma_address,
- sg->length, dir,
- DMA_ATTR_SKIP_CPU_SYNC);
+ if (dev) {
+ for_each_sgtable_sg(sgt, sg, i)
+ dma_unmap_resource(dev, sg->dma_address,
+ sg->length, dir,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ }
sg_free_table(sgt);
kfree(sgt);
}
PATCH v3 7/7 drm/amdkfd: Bump kfd version for contiguous VRAM allocation
In reply to Philip YangBump the kfd ioctl minor version to delcare the contiguous VRAM allocation flag support.
--- include/uapi/linux/kfd_ioctl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/kfd_ioctl.h +2 -1
@@ -41,9 +41,10 @@* - 1.13 - Add debugger API * - 1.14 - Update kfd_event_data * - 1.15 - Enable managing mappings in compute VMs with GEM_VA ioctl +* - 1.16 - Add contiguous VRAM allocation flag */ #define KFD_IOCTL_MAJOR_VERSION 1 -#define KFD_IOCTL_MINOR_VERSION 15 +#define KFD_IOCTL_MINOR_VERSION 16struct kfd_ioctl_get_version_args {__u32 major_version;/* from KFD */
Signature · 1 line
2.43.2