I'm writing a kernel module that would write some data to user space buffer via copy_to_user
. However, I found that copy_to_user
always fails (returns non-zero) after the process forks. (copy_to_user
works fine if I don't fork the process.) copy_to_user
was called right after forked and I've used access_ok
to check accessibility of the destination address.
I'm aware that after forking, child process will share meory with parent process due to copy-on-write mechanism. So I assume the reason that copy_to_user
failed after fork might due to COW page fault.
My questions are,
- Is my assumption about COW mechanism causing
copy_to_user
failed true? - If above is true, why didn't kernel handle page fault? Or What should I do to make
copy_to_user
work after process fork?