Skip to content

Commit b5f022f

Browse files
EmilyDeng666alexdeucher
authored andcommitted
drm/amdkfd: Fix partial migrate issue
For partial migrate from ram to vram, the migrate->cpages is not equal to migrate->npages, should use migrate->npages to check all needed migrate pages which could be copied or not. And only need to set those pages could be migrated to migrate->dst[i], or the migrate_vma_pages will migrate the wrong pages based on the migrate->dst[i]. v2: Add mpages to break the loop earlier. v3: Uses MIGRATE_PFN_MIGRATE to identify whether page could be migrated. v4: Correct the error part. Signed-off-by: Emily Deng <[email protected]> Reviewed-by: Philip Yang<[email protected]> Suggested-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 19b7f7c commit b5f022f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
278278
struct migrate_vma *migrate, struct dma_fence **mfence,
279279
dma_addr_t *scratch, uint64_t ttm_res_offset)
280280
{
281-
uint64_t npages = migrate->cpages;
281+
uint64_t npages = migrate->npages;
282282
struct amdgpu_device *adev = node->adev;
283283
struct device *dev = adev->dev;
284284
struct amdgpu_res_cursor cursor;
285+
uint64_t mpages = 0;
285286
dma_addr_t *src;
286287
uint64_t *dst;
287288
uint64_t i, j;
@@ -295,14 +296,16 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
295296

296297
amdgpu_res_first(prange->ttm_res, ttm_res_offset,
297298
npages << PAGE_SHIFT, &cursor);
298-
for (i = j = 0; i < npages; i++) {
299+
for (i = j = 0; (i < npages) && (mpages < migrate->cpages); i++) {
299300
struct page *spage;
300301

301-
dst[i] = cursor.start + (j << PAGE_SHIFT);
302-
migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]);
303-
svm_migrate_get_vram_page(prange, migrate->dst[i]);
304-
migrate->dst[i] = migrate_pfn(migrate->dst[i]);
305-
302+
if (migrate->src[i] & MIGRATE_PFN_MIGRATE) {
303+
dst[i] = cursor.start + (j << PAGE_SHIFT);
304+
migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]);
305+
svm_migrate_get_vram_page(prange, migrate->dst[i]);
306+
migrate->dst[i] = migrate_pfn(migrate->dst[i]);
307+
mpages++;
308+
}
306309
spage = migrate_pfn_to_page(migrate->src[i]);
307310
if (spage && !is_zone_device_page(spage)) {
308311
src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE,
@@ -353,9 +356,12 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,
353356
out_free_vram_pages:
354357
if (r) {
355358
pr_debug("failed %d to copy memory to vram\n", r);
356-
while (i--) {
359+
for (i = 0; i < npages && mpages; i++) {
360+
if (!dst[i])
361+
continue;
357362
svm_migrate_put_vram_page(adev, dst[i]);
358363
migrate->dst[i] = 0;
364+
mpages--;
359365
}
360366
}
361367

0 commit comments

Comments
 (0)