drm/amdkfd: use vma_lookup() instead of find_vma()
authorDeming Wang <wangdeming@inspur.com>
Fri, 7 Oct 2022 02:26:51 +0000 (22:26 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 24 Oct 2022 18:34:47 +0000 (14:34 -0400)
Using vma_lookup() verifies the start address is contained in the found
vma.  This results in easier to read the code.

Signed-off-by: Deming Wang <wangdeming@inspur.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
drivers/gpu/drm/amd/amdkfd/kfd_svm.c

index 2797029..d4e6de2 100644 (file)
@@ -529,8 +529,8 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
        for (addr = start; addr < end;) {
                unsigned long next;
 
-               vma = find_vma(mm, addr);
-               if (!vma || addr < vma->vm_start)
+               vma = vma_lookup(mm, addr);
+               if (!vma)
                        break;
 
                next = min(vma->vm_end, end);
@@ -798,8 +798,8 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm,
        for (addr = start; addr < end;) {
                unsigned long next;
 
-               vma = find_vma(mm, addr);
-               if (!vma || addr < vma->vm_start) {
+               vma = vma_lookup(mm, addr);
+               if (!vma) {
                        pr_debug("failed to find vma for prange %p\n", prange);
                        r = -EFAULT;
                        break;
index 64fdf63..0100812 100644 (file)
@@ -1586,8 +1586,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
                unsigned long npages;
                bool readonly;
 
-               vma = find_vma(mm, addr);
-               if (!vma || addr < vma->vm_start) {
+               vma = vma_lookup(mm, addr);
+               if (!vma) {
                        r = -EFAULT;
                        goto unreserve_out;
                }
@@ -2542,8 +2542,8 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
        struct interval_tree_node *node;
        unsigned long start_limit, end_limit;
 
-       vma = find_vma(p->mm, addr << PAGE_SHIFT);
-       if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) {
+       vma = vma_lookup(p->mm, addr << PAGE_SHIFT);
+       if (!vma) {
                pr_debug("VMA does not exist in address [0x%llx]\n", addr);
                return -EFAULT;
        }
@@ -2871,8 +2871,8 @@ retry_write_locked:
        /* __do_munmap removed VMA, return success as we are handling stale
         * retry fault.
         */
-       vma = find_vma(mm, addr << PAGE_SHIFT);
-       if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) {
+       vma = vma_lookup(mm, addr << PAGE_SHIFT);
+       if (!vma) {
                pr_debug("address 0x%llx VMA is removed\n", addr);
                r = 0;
                goto out_unlock_range;
@@ -3152,9 +3152,8 @@ svm_range_is_valid(struct kfd_process *p, uint64_t start, uint64_t size)
        start <<= PAGE_SHIFT;
        end = start + (size << PAGE_SHIFT);
        do {
-               vma = find_vma(p->mm, start);
-               if (!vma || start < vma->vm_start ||
-                   (vma->vm_flags & device_vma))
+               vma = vma_lookup(p->mm, start);
+               if (!vma || (vma->vm_flags & device_vma))
                        return -EFAULT;
                start = min(end, vma->vm_end);
        } while (start < end);