Commit 9473b6b2 authored by Xiaogang Chen's avatar Xiaogang Chen Committed by Alex Deucher

drm/amdkfd: Fix BO offset for multi-VMA page migration

svm_migrate_ram_to_vram migrates a prange from sys ram to vram. The prange may
cross multiple vma. Need remember current dst vram offset in the TTM resource for
each migration.

v2: squash in warning fix (Alex)
Signed-off-by: default avatarXiaogang Chen <Xiaogang.Chen@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 7a1bb27b
...@@ -289,7 +289,7 @@ static unsigned long svm_migrate_unsuccessful_pages(struct migrate_vma *migrate) ...@@ -289,7 +289,7 @@ static unsigned long svm_migrate_unsuccessful_pages(struct migrate_vma *migrate)
static int static int
svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange, svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
struct migrate_vma *migrate, struct dma_fence **mfence, struct migrate_vma *migrate, struct dma_fence **mfence,
dma_addr_t *scratch) dma_addr_t *scratch, uint64_t ttm_res_offset)
{ {
uint64_t npages = migrate->npages; uint64_t npages = migrate->npages;
struct device *dev = adev->dev; struct device *dev = adev->dev;
...@@ -299,8 +299,8 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange, ...@@ -299,8 +299,8 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
uint64_t i, j; uint64_t i, j;
int r; int r;
pr_debug("svms 0x%p [0x%lx 0x%lx]\n", prange->svms, prange->start, pr_debug("svms 0x%p [0x%lx 0x%lx 0x%llx]\n", prange->svms, prange->start,
prange->last); prange->last, ttm_res_offset);
src = scratch; src = scratch;
dst = (uint64_t *)(scratch + npages); dst = (uint64_t *)(scratch + npages);
...@@ -311,7 +311,7 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange, ...@@ -311,7 +311,7 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
goto out; goto out;
} }
amdgpu_res_first(prange->ttm_res, prange->offset << PAGE_SHIFT, amdgpu_res_first(prange->ttm_res, ttm_res_offset,
npages << PAGE_SHIFT, &cursor); npages << PAGE_SHIFT, &cursor);
for (i = j = 0; i < npages; i++) { for (i = j = 0; i < npages; i++) {
struct page *spage; struct page *spage;
...@@ -398,7 +398,7 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange, ...@@ -398,7 +398,7 @@ svm_migrate_copy_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
static long static long
svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
struct vm_area_struct *vma, uint64_t start, struct vm_area_struct *vma, uint64_t start,
uint64_t end, uint32_t trigger) uint64_t end, uint32_t trigger, uint64_t ttm_res_offset)
{ {
struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms); struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms);
uint64_t npages = (end - start) >> PAGE_SHIFT; uint64_t npages = (end - start) >> PAGE_SHIFT;
...@@ -451,7 +451,7 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange, ...@@ -451,7 +451,7 @@ svm_migrate_vma_to_vram(struct amdgpu_device *adev, struct svm_range *prange,
else else
pr_debug("0x%lx pages migrated\n", cpages); pr_debug("0x%lx pages migrated\n", cpages);
r = svm_migrate_copy_to_vram(adev, prange, &migrate, &mfence, scratch); r = svm_migrate_copy_to_vram(adev, prange, &migrate, &mfence, scratch, ttm_res_offset);
migrate_vma_pages(&migrate); migrate_vma_pages(&migrate);
pr_debug("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n", pr_debug("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n",
...@@ -499,6 +499,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -499,6 +499,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
unsigned long addr, start, end; unsigned long addr, start, end;
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct amdgpu_device *adev; struct amdgpu_device *adev;
uint64_t ttm_res_offset;
unsigned long cpages = 0; unsigned long cpages = 0;
long r = 0; long r = 0;
...@@ -519,6 +520,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -519,6 +520,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
start = prange->start << PAGE_SHIFT; start = prange->start << PAGE_SHIFT;
end = (prange->last + 1) << PAGE_SHIFT; end = (prange->last + 1) << PAGE_SHIFT;
ttm_res_offset = prange->offset << PAGE_SHIFT;
for (addr = start; addr < end;) { for (addr = start; addr < end;) {
unsigned long next; unsigned long next;
...@@ -528,13 +530,14 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -528,13 +530,14 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
break; break;
next = min(vma->vm_end, end); next = min(vma->vm_end, end);
r = svm_migrate_vma_to_vram(adev, prange, vma, addr, next, trigger); r = svm_migrate_vma_to_vram(adev, prange, vma, addr, next, trigger, ttm_res_offset);
if (r < 0) { if (r < 0) {
pr_debug("failed %ld to migrate\n", r); pr_debug("failed %ld to migrate\n", r);
break; break;
} else { } else {
cpages += r; cpages += r;
} }
ttm_res_offset += next - addr;
addr = next; addr = next;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment