<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Sent:</b> Thursday, April 21, 2022 10:55 PM<br>
<b>To:</b> Wang, Yang(Kevin) <KevinYang.Wang@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH] drm/amdkfd: use kvcalloc() instead of kvmalloc() in kfd_migrate</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">Am 2022-04-21 um 08:33 schrieb Yang Wang:<br>
> simplify programming with existing functions.<br>
><br>
> Signed-off-by: Yang Wang <KevinYang.Wang@amd.com><br>
<br>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com><br>
<br>
There is one more kvmalloc_array call with GFP_ZERO that could be <br>
replaced with kvcalloc in svm_range_dma_map_dev in kfd_svm.c. Maybe fix <br>
that one as well while you're at it.<br>
<br>
Regards,<br>
Felix<br>
<br>
[kevin]:</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">Thanks for reminder.</div>
<div class="PlainText elementToProof">I will fix it before submitting.<br>
</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">Best Regards,</div>
<div class="PlainText elementToProof">Kevin</div>
<div class="PlainText elementToProof"><br>
> ---<br>
> drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 15 +++++++--------<br>
> 1 file changed, 7 insertions(+), 8 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
> index 3a29d857640b..43cd47723946 100644<br>
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
> @@ -410,7 +410,6 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,<br>
> struct migrate_vma migrate;<br>
> unsigned long cpages = 0;<br>
> dma_addr_t *scratch;<br>
> - size_t size;<br>
> void *buf;<br>
> int r = -ENOMEM;<br>
> <br>
> @@ -421,9 +420,9 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,<br>
> migrate.flags = MIGRATE_VMA_SELECT_SYSTEM;<br>
> migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev);<br>
> <br>
> - size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t);<br>
> - size *= npages;<br>
> - buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO);<br>
> + buf = kvcalloc(npages,<br>
> + 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t),<br>
> + GFP_KERNEL);<br>
> if (!buf)<br>
> goto out;<br>
> <br>
> @@ -665,7 +664,6 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,<br>
> struct dma_fence *mfence = NULL;<br>
> struct migrate_vma migrate;<br>
> dma_addr_t *scratch;<br>
> - size_t size;<br>
> void *buf;<br>
> int r = -ENOMEM;<br>
> <br>
> @@ -676,9 +674,10 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,<br>
> migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE;<br>
> migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev);<br>
> <br>
> - size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t);<br>
> - size *= npages;<br>
> - buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO);<br>
> + buf = kvcalloc(npages,<br>
> + 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t),<br>
> + GFP_KERNEL);<br>
> +<br>
> if (!buf)<br>
> goto out;<br>
> <br>
</div>
</span></font></div>
</div>
</body>
</html>