Last active
June 14, 2021 10:40
-
-
Save paranlee/016da7a549de697116ad82bb3c542fcc to your computer and use it in GitHub Desktop.
Try to Study Rmap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Rmap Study in Linux Kernel v5.1 | |
| * | |
| * [kernel/fork.c -> rmap.c] rmap init routine. | |
| * | |
| * do_fork [kernel/fork.c] | |
| * - _do_fork [kernel/fork.c] | |
| * -- copy_process [kernel/fork.c] | |
| * --- copy_mm [kernel/fork.c] | |
| * | |
| * ---- static struct mm_struct *dup_mm(struct task_struct *tsk) [kernel/fork.c] | |
| * | |
| * struct mm_struct *mm, *oldmm = current->mm; | |
| int err; | |
| mm = allocate_mm(); | |
| // ... | |
| * if (!mm_init(mm, tsk, mm->user_ns)) | |
| goto fail_nomem; | |
| * ... | |
| * | |
| * See Below source code. | |
| * | |
| * ----- dup_mmap [kernel/fork.c] | |
| * tmp = vm_area_dup(mpnt); | |
| * this make (struct vm_area_struct *vma) new VMA | |
| * | |
| * then, | |
| * | |
| * Call anon_vma_prepare(new VMA) [mm/rmap.c] | |
| * OR | |
| * Call anon_vma_fork(new VMA, parent VMA) [mm/rmap.c] | |
| */ | |
| #ifdef CONFIG_MMU | |
| static __latent_entropy int dup_mmap(struct mm_struct *mm, | |
| struct mm_struct *oldmm) | |
| // ... | |
| for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { | |
| // ... | |
| tmp = vm_area_dup(mpnt); | |
| if (!tmp) | |
| goto fail_nomem; | |
| retval = vma_dup_policy(mpnt, tmp); | |
| if (retval) | |
| goto fail_nomem_policy; | |
| tmp->vm_mm = mm; | |
| retval = dup_userfaultfd(tmp, &uf); | |
| if (retval) | |
| goto fail_nomem_anon_vma_fork; | |
| if (tmp->vm_flags & VM_WIPEONFORK) { | |
| /* VM_WIPEONFORK gets a clean slate in the child. */ | |
| tmp->anon_vma = NULL; | |
| if (anon_vma_prepare(tmp)) | |
| goto fail_nomem_anon_vma_fork; | |
| } else if (anon_vma_fork(tmp, mpnt)) | |
| goto fail_nomem_anon_vma_fork; | |
| // ... file ... | |
| } | |
| // ... | |
| fail_nomem_anon_vma_fork: | |
| mpol_put(vma_policy(tmp)); | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment