drm/amdkfd: use kvcalloc() instead of kvmalloc() in kfd_migrate
Subsystems (3)
PATCH 1/1 drm/amdkfd: use kvcalloc() instead of kvmalloc() in kfd_migrate
simplify programming with existing functions.
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +7 -8
@@ -410,7 +410,6 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,struct migrate_vma migrate;unsigned long cpages =0 ;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;
@@ -421,9 +420,9 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_SYSTEM ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL );if (!buf) goto out;
@@ -665,7 +664,6 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;
@@ -676,9 +674,10 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_DEVICE_PRIVATE ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL ); +if (!buf) goto out;
Signature · 1 line
2.25.1
Quoted 4 lines · Yang Wang
simplify programming with existing functions.
Signed-off-by Yang Wang <[email protected]>
Quoted 54 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +7
-9@@ -410,7 +410,6 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,struct migrate_vma migrate;unsigned long cpages =0 ;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -421,9 +420,9 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_SYSTEM ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL );if (!buf) goto out;@@ -665,7 +664,6 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -676,9 +674,10 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_DEVICE_PRIVATE ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL ); +if (!buf) goto out; --2.25.1
Am 2022-04-21 um 08:33 schrieb Yang Wang:
Quoted 3 lines
simplify programming with existing functions.
Signed-off-by Yang Wang <[email protected]>
There is one more kvmalloc_array call with GFP_ZERO that could be replaced with kvcalloc in svm_range_dma_map_dev in kfd_svm.c. Maybe fix that one as well while you're at it.
Regards,
Felix
Quoted 51 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +7
-8@@ -410,7 +410,6 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,struct migrate_vma migrate;unsigned long cpages =0 ;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -421,9 +420,9 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_SYSTEM ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL );if (!buf) goto out;@@ -665,7 +664,6 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -676,9 +674,10 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_DEVICE_PRIVATE ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL ); +if (!buf) goto out;
Wang, Yang(Kevin)
Reviewed-by Felix Kuehling[AMD Official Use Only]
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Thursday, April 21, 2022 10:55 PM
To: Wang, Yang(Kevin) <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: use kvcalloc() instead of kvmalloc() in kfd_migrate
Am 2022-04-21 um 08:33 schrieb Yang Wang:
Quoted 3 lines
simplify programming with existing functions.
Signed-off-by Yang Wang <[email protected]>
There is one more kvmalloc_array call with GFP_ZERO that could be replaced with kvcalloc in svm_range_dma_map_dev in kfd_svm.c. Maybe fix that one as well while you're at it.
Regards,
Felix
[kevin]:
Thanks for reminder.
I will fix it before submitting.
Best Regards,
Kevin
Quoted 51 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +7
-8@@ -410,7 +410,6 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,struct migrate_vma migrate;unsigned long cpages =0 ;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -421,9 +420,9 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_SYSTEM ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL );if (!buf) goto out;@@ -665,7 +664,6 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate;dma_addr_t *scratch; -size_t size;void *buf;int r = -ENOMEM ;@@ -676,9 +674,10 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_DEVICE_PRIVATE ; migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); - size =2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t); - size *= npages; - buf =kvmalloc (size,GFP_KERNEL | __GFP_ZERO); + buf =kvcalloc (npages, +2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +GFP_KERNEL ); +if (!buf) goto out;