Skip to content

Commit 7ad153d

Browse files
PhilipYangAalexdeucher
authored andcommitted
drm/amdkfd: handle VMA remove race
VMA may be removed before unmap notifier callback, and deferred list work remove range, return success for this special case as we are handling stale retry fault. Signed-off-by: Philip Yang <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent a0c55ec commit 7ad153d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_svm.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,20 +2548,13 @@ svm_range_count_fault(struct amdgpu_device *adev, struct kfd_process *p,
25482548
}
25492549

25502550
static bool
2551-
svm_fault_allowed(struct mm_struct *mm, uint64_t addr, bool write_fault)
2551+
svm_fault_allowed(struct vm_area_struct *vma, bool write_fault)
25522552
{
25532553
unsigned long requested = VM_READ;
2554-
struct vm_area_struct *vma;
25552554

25562555
if (write_fault)
25572556
requested |= VM_WRITE;
25582557

2559-
vma = find_vma(mm, addr << PAGE_SHIFT);
2560-
if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) {
2561-
pr_debug("address 0x%llx VMA is removed\n", addr);
2562-
return true;
2563-
}
2564-
25652558
pr_debug("requested 0x%lx, vma permission flags 0x%lx\n", requested,
25662559
vma->vm_flags);
25672560
return (vma->vm_flags & requested) == requested;
@@ -2579,6 +2572,7 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,
25792572
int32_t best_loc;
25802573
int32_t gpuidx = MAX_GPU_INSTANCE;
25812574
bool write_locked = false;
2575+
struct vm_area_struct *vma;
25822576
int r = 0;
25832577

25842578
if (!KFD_IS_SVM_API_SUPPORTED(adev->kfd.dev)) {
@@ -2654,7 +2648,17 @@ svm_range_restore_pages(struct amdgpu_device *adev, unsigned int pasid,
26542648
goto out_unlock_range;
26552649
}
26562650

2657-
if (!svm_fault_allowed(mm, addr, write_fault)) {
2651+
/* __do_munmap removed VMA, return success as we are handling stale
2652+
* retry fault.
2653+
*/
2654+
vma = find_vma(mm, addr << PAGE_SHIFT);
2655+
if (!vma || (addr << PAGE_SHIFT) < vma->vm_start) {
2656+
pr_debug("address 0x%llx VMA is removed\n", addr);
2657+
r = 0;
2658+
goto out_unlock_range;
2659+
}
2660+
2661+
if (!svm_fault_allowed(vma, write_fault)) {
26582662
pr_debug("fault addr 0x%llx no %s permission\n", addr,
26592663
write_fault ? "write" : "read");
26602664
r = -EPERM;

0 commit comments

Comments
 (0)