[PATCH v3 14/14] mm: fork: Enable COW PTE to fork system call

From: Chih-En Lin
Date: Tue Dec 20 2022 - 02:28:55 EST


This patch enables the Copy-On-Write (COW) mechanism to the PTE table
in fork system call. To let the process do COW PTE fork, use
prctl(PR_SET_COW_PTE), it will set the MMF_COW_PTE_READY flag to the
process for enabling COW PTE during the next time of fork.

It uses the MMF_COW_PTE flag to distinguish the normal page table
and the COW one. Moreover, it is difficult to distinguish whether all
the page tables is out of COW state. So the MMF_COW_PTE flag won't be
disabled after setup.

Signed-off-by: Chih-En Lin <shiyn.lin@xxxxxxxxx>
---
kernel/fork.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/fork.c b/kernel/fork.c
index 08969f5aa38d5..ef3d27577aa43 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2668,6 +2668,11 @@ pid_t kernel_clone(struct kernel_clone_args *args)
trace = 0;
}

+ if (current->mm && test_bit(MMF_COW_PTE_READY, &current->mm->flags)) {
+ clear_bit(MMF_COW_PTE_READY, &current->mm->flags);
+ set_bit(MMF_COW_PTE, &current->mm->flags);
+ }
+
p = copy_process(NULL, trace, NUMA_NO_NODE, args);
add_latent_entropy();

--
2.37.3