Skip to content

Commit

Permalink
drm/amdkfd: handle svm migrate.cpages reset to 0
Browse files Browse the repository at this point in the history
In older kernel version 5.9, migrate.cpages reset to 0 by
migrate_vma_finalize, so use local variable to save migrate.cpages. This
change work for older kernels and upstream kernel.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
  • Loading branch information
Philip Yang authored and Philip Yang committed Oct 15, 2021
1 parent df11094 commit 57ca141
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
struct kfd_process_device *pdd;
struct dma_fence *mfence = NULL;
struct migrate_vma migrate;
unsigned long cpages = 0;
dma_addr_t *scratch;
size_t size;
void *buf;
Expand Down Expand Up @@ -480,17 +481,17 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
goto out_free;
}

if (migrate.cpages != npages)
pr_debug("partial migration, 0x%lx/0x%llx pages migrated\n",
migrate.cpages, npages);
else
pr_debug("0x%lx pages migrated\n", migrate.cpages);

if (!migrate.cpages) {
cpages = migrate.cpages;
if (!cpages) {
pr_debug("failed collect migrate sys pages [0x%lx 0x%lx]\n",
prange->start, prange->last);
goto out_free;
}
if (cpages != npages)
pr_debug("partial migration, 0x%lx/0x%llx pages migrated\n",
cpages, npages);
else
pr_debug("0x%lx pages migrated\n", cpages);

r = svm_migrate_copy_to_vram(adev, prange, &migrate, &mfence, scratch);
migrate_vma_pages(&migrate);
Expand All @@ -503,12 +504,12 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
out_free:
kvfree(buf);
out:
if (!r && migrate.cpages) {
if (!r && cpages) {
pdd = svm_range_get_pdd_by_adev(prange, adev);
if (pdd)
WRITE_ONCE(pdd->page_in, pdd->page_in + migrate.cpages);
WRITE_ONCE(pdd->page_in, pdd->page_in + cpages);

return migrate.cpages;
return cpages;
}
return r;
}
Expand Down Expand Up @@ -685,6 +686,7 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
struct kfd_process_device *pdd;
struct dma_fence *mfence = NULL;
struct migrate_vma migrate;
unsigned long cpages = 0;
dma_addr_t *scratch;
size_t size;
void *buf;
Expand Down Expand Up @@ -723,17 +725,17 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
goto out_free;
}

if (migrate.cpages != npages)
pr_debug("partial migration, 0x%lx/0x%llx pages migrated\n",
migrate.cpages, npages);
else
pr_debug("0x%lx pages migrated\n", migrate.cpages);

if (!migrate.cpages) {
cpages = migrate.cpages;
if (!cpages) {
pr_debug("failed collect migrate device pages [0x%lx 0x%lx]\n",
prange->start, prange->last);
goto out_free;
}
if (cpages != npages)
pr_debug("partial migration, 0x%lx/0x%llx pages migrated\n",
cpages, npages);
else
pr_debug("0x%lx pages migrated\n", cpages);

r = svm_migrate_copy_to_ram(adev, prange, &migrate, &mfence,
scratch, npages);
Expand All @@ -745,13 +747,12 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
out_free:
kvfree(buf);
out:
if (!r && migrate.cpages) {
if (!r && cpages) {
pdd = svm_range_get_pdd_by_adev(prange, adev);
if (pdd)
WRITE_ONCE(pdd->page_out,
pdd->page_out + migrate.cpages);
WRITE_ONCE(pdd->page_out, pdd->page_out + cpages);

return migrate.cpages;
return cpages;
}
return r;
}
Expand Down

0 comments on commit 57ca141

Please sign in to comment.