Commit 3a3e841d authored by Deming Wang's avatar Deming Wang Committed by Alex Deucher

drm/amdkfd: use vma_lookup() instead of find_vma()

Using vma_lookup() verifies the start address is contained in the found
vma.  This results in easier to read the code.
Signed-off-by: default avatarDeming Wang <wangdeming@inspur.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 178919f8
...@@ -529,8 +529,8 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -529,8 +529,8 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
for (addr = start; addr < end;) { for (addr = start; addr < end;) {
unsigned long next; unsigned long next;
vma = find_vma(mm, addr); vma = vma_lookup(mm, addr);
if (!vma || addr < vma->vm_start) if (!vma)
break; break;
next = min(vma->vm_end, end); next = min(vma->vm_end, end);
...@@ -798,8 +798,8 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm, ...@@ -798,8 +798,8 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm,
for (addr = start; addr < end;) { for (addr = start; addr < end;) {
unsigned long next; unsigned long next;
vma = find_vma(mm, addr); vma = vma_lookup(mm, addr);
if (!vma || addr < vma->vm_start) { if (!vma) {
pr_debug("failed to find vma for prange %p\n", prange); pr_debug("failed to find vma for prange %p\n", prange);
r = -EFAULT; r = -EFAULT;
break; break;
......
...@@ -1586,8 +1586,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm, ...@@ -1586,8 +1586,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
unsigned long npages; unsigned long npages;
bool readonly; bool readonly;
vma = find_vma(mm, addr); vma = vma_lookup(mm, addr);
if (!vma || addr < vma->vm_start) { if (!vma) {
r = -EFAULT; r = -EFAULT;
goto unreserve_out; goto unreserve_out;
} }
...@@ -2542,8 +2542,8 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr, ...@@ -2542,8 +2542,8 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
struct interval_tree_node *node; struct interval_tree_node *node;
unsigned long start_limit, end_limit; unsigned long start_limit, end_limit;
vma = find_vma(p->mm, addr << PAGE_SHIFT); vma = vma_lookup(p->mm, addr << PAGE_SHIFT);
if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) { if (!vma) {
pr_debug("VMA does not exist in address [0x%llx]\n", addr); pr_debug("VMA does not exist in address [0x%llx]\n", addr);
return -EFAULT; return -EFAULT;
} }
...@@ -2871,8 +2871,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid, ...@@ -2871,8 +2871,8 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,
/* __do_munmap removed VMA, return success as we are handling stale /* __do_munmap removed VMA, return success as we are handling stale
* retry fault. * retry fault.
*/ */
vma = find_vma(mm, addr << PAGE_SHIFT); vma = vma_lookup(mm, addr << PAGE_SHIFT);
if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) { if (!vma) {
pr_debug("address 0x%llx VMA is removed\n", addr); pr_debug("address 0x%llx VMA is removed\n", addr);
r = 0; r = 0;
goto out_unlock_range; goto out_unlock_range;
...@@ -3152,9 +3152,8 @@ svm_range_is_valid(struct kfd_process *p, uint64_t start, uint64_t size) ...@@ -3152,9 +3152,8 @@ svm_range_is_valid(struct kfd_process *p, uint64_t start, uint64_t size)
start <<= PAGE_SHIFT; start <<= PAGE_SHIFT;
end = start + (size << PAGE_SHIFT); end = start + (size << PAGE_SHIFT);
do { do {
vma = find_vma(p->mm, start); vma = vma_lookup(p->mm, start);
if (!vma || start < vma->vm_start || if (!vma || (vma->vm_flags & device_vma))
(vma->vm_flags & device_vma))
return -EFAULT; return -EFAULT;
start = min(end, vma->vm_end); start = min(end, vma->vm_end);
} while (start < end); } while (start < end);
......
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