drm/amdkfd: use vma_lookup() instead of find_vma()
Subsystems (3)
PATCH 1/1 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.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +6 -6
@@ -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 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,/* __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;
Signature · 1 line
2.27.0
Felix Kuehling
maintainerQuoted 2 lines · Deming Wang
Using
vma_lookup()verifies the start address is contained in the found vma. This results in easier to read the code.
Thank you for the patches. This and your other patch look good to me. However, you missed one use of find_vma in svm_range_is_valid. Is that an oversight or is there a reason why we need to use find_vma there?
If you're going to respin it, you may also squash the two patches into one.
Thanks,
Felix
Quoted 43 lines
Signed-off-by Deming Wang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +6
-6@@ -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 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,/* __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;
Hi,
The function vma_lookup show below. Vma valid check is included in it. Or, What other questions do you have?
static inline
struct vm_area_struct *vma_lookup(struct mm_struct *mm, unsigned long addr)
{
struct vm_area_struct *vma = find_vma(mm, addr);
if (vma && addr < vma->vm_start)
vma = NULL;
return vma;}
Quoted 70 lines
from: Felix Kuehling <[email protected]>
time: 2022年10月18日 3:35
to: tomorrow Wang (王德明) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] [email protected]
sub: Re: [PATCH] drm/amdkfd: usevma_lookup()instead offind_vma()Quoted 2 lines · Deming Wang
Using
vma_lookup()verifies the start address is contained in the found vma. This results in easier to read the code.Thank you for the patches. This and your other patch look good to me. However, you missed one use of
find_vmainsvm_range_is_valid. Is that an oversight or is there a reason why we need to usefind_vmathere?If you're going to respin it, you may also squash the two patches into one.
Thanks,
Felixdrivers/gpu/drm/amd/amdkfd/kfd_svm.c static int svm_range_validate_and_map(struct
Quoted 12 lines
Signed-off-by Deming Wang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0@@ -1586,8 +1586,8 @@ static int svm_range_validate_and_map(struct
mm_struct*mm,drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_get_range_boundaries(struct
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2unsigned 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_taddr,drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_restore_pages(struct amdgpu_device
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2struct 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 @@ svm_range_restore_pages(struct amdgpu_device*adev, unsigned int pasid,
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2/* __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;
Felix Kuehling
maintainerAm 2022-10-17 um 20:47 schrieb tomorrow Wang (王德明):
Quoted 2 lines
Hi,
The functionvma_lookupshow below. Vma valid check is included in it. Or, What other questions do you have?
My question is, why did you leave the find_vma call in svm_range_is_valid unchanged? I don't see a technical reason, but maybe I'm missing something. If there is a reason, please explain. If there is no reason, please fix that place as well for consistency.
Thanks,
Felix
Quoted 81 lines
static inline
structvm_area_struct*vma_lookup(structmm_struct*mm, unsigned long addr){ struct vm_area_struct *vma = find_vma(mm, addr); if (vma && addr < vma->vm_start) vma = NULL; return vma;}
Quoted 68 lines
from: Felix Kuehling <[email protected]>
time: 2022年10月18日 3:35
to: tomorrow Wang (王德明) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] [email protected]
sub: Re: [PATCH] drm/amdkfd: usevma_lookup()instead offind_vma()Quoted 2 lines · Deming Wang
Using
vma_lookup()verifies the start address is contained in the found vma. This results in easier to read the code.Thank you for the patches. This and your other patch look good to me. However, you missed one use of
find_vmainsvm_range_is_valid. Is that an oversight or is there a reason why we need to usefind_vmathere?If you're going to respin it, you may also squash the two patches into one.
Thanks,
Felixdrivers/gpu/drm/amd/amdkfd/kfd_svm.c static int svm_range_validate_and_map(struct
Quoted 11 lines
Signed-off-by Deming Wang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0@@ -1586,8 +1586,8 @@ static int svm_range_validate_and_map(struct
mm_struct*mm,drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_get_range_boundaries(struct
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2unsigned 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_taddr,drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_restore_pages(struct amdgpu_device
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2struct 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 @@ svm_range_restore_pages(struct amdgpu_device*adev, unsigned int pasid,
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-2/* __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;