I would like to write a kernel function/module that will duplicate a specific page from a specific process, and then free that particular page. The module/function will then do whatever necessary to force that process into a page fault the next time it references the page.

The page fault then will be served using the duplicate that was kept aside. I can intercept page fault using the vm_operations_struct or by modifying the handle_mm_fault function in the kernel.

The part I am not sure how to do is freeing the page and forcing the process into a page fault.

Here is the planned test that will explain in details what I want to do:

  • start a test process, suspend it and pass its pid to kernel module/function.
  • The kernel function will use the pid to a get pointer to the mm struct of that process.
  • The kernel function, then, chooses a page from the process (say a heap page), copies it into another page, and then assign the vm_ops pointer for that vm_area_struct to my own vm_operations_struct.
  • The kernel function then frees the page and flushes it from the cpu.
  • The kernel function then sends a SIGCONT to the process.
  • Once the process resumes it will run into a page fault. The page fault will be intercepted using the vm_ops pointer, which will will cal my function to serve the page fault. My fault handler will use the duplicate page to serve the page fault.

My question is related to the step in bold.

I need to figure out how to do this. Any idea?

Thanks.

有帮助吗?

解决方案

After looking into this for a while seems like try_to_unmap is the function I am looking for.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top