On 2024-02-21 21:01, Lang Yu wrote:
This is useful to prevent copy-on-write semantics from changing the physical location of a page if the parent writes to it after a fork(). Signed-off-by: Lang Yu <Lang.Yu@xxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 75c9fd2c6c2a..2ee0af3c41b1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -693,6 +693,7 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages, } readonly = amdgpu_ttm_tt_is_readonly(ttm); + vm_flags_set(vma, VM_DONTCOPY);
This will break user mode because the forked child process cannot access this vma/userptr.
This can be set by application if needed, using madvise(...MADV_DONTFORK) to avoid COW after fork.
Regards,
Philip
r = amdgpu_hmm_range_get_pages(&bo->notifier, start, ttm->num_pages, readonly, NULL, pages, range); out_unlock: diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c index 6aa032731ddc..607a8f68f26f 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -1674,6 +1674,7 @@ static int svm_range_validate_and_map(struct mm_struct *mm, next = min(vma->vm_end, end); npages = (next - addr) >> PAGE_SHIFT; WRITE_ONCE(p->svms.faulting_task, current); + vm_flags_set(vma, VM_DONTCOPY); r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages, readonly, owner, NULL, &hmm_range);