简体   繁体   English

如何在Linux内核中解决页面错误?

[英]How to serve a page fault in the linux kernel?

I am working on a project that requires heavy modifications in the Linux kernel. 我正在一个需要在Linux内核中进行大量修改的项目。 In one of the modifications I have to change the way the page fault handler works. 在其中一项修改中,我必须更改页面错误处理程序的工作方式。 I would like to be to intercept page faults from specific processes and satisfy them possible by getting copying data from another machine. 我想拦截来自特定进程的页面错误,并通过从另一台计算机上复制数据来满足它们的可能。

As a first step, I would like to write some experimentation code that can help me understand how Linux satisfies a page fault and how it also tells the process that the page fault can not be served right now and it needs to do a retry at a later time. 第一步,我想编写一些实验代码,这些代码可以帮助我了解Linux如何满足页面错误,以及如何告诉该过程当前无法解决页面错误,并且需要在网络上重试。晚点。

So, I would like to modify handle_mm_fault in a way that helps me understand all the above. 因此,我想以一种有助于我理解以上所有内容的方式修改handle_mm_fault Something like this: 像这样:

int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
                     unsigned long address, unsigned int flags)
{
     /* some code */
     if(current->pid == my_target_pid)
     {
         /*
          1. Chose randomly between 1 and 2 -> rand_num
          2. if rand_num from (1) is 1 then allocate a block of memory, write 'X's to it and then give it to the process and then return.
          3. if rand_num from (1) is 2 then tell process to come back later and then return.
         */
     }
     /* rest of handle_mm_fault for all other process here */
}

You can have a look at the struct vm_operations_struct . 您可以看一下struct vm_operations_struct Its function member 'fault' is used to deal with the page fault situation 它的功能成员'fault'用于处理页面错误情况

The question you described sound like page demanding for data abort. 您描述的问题听起来像页面要求数据中止。 First of all, data abort could happen because of invalid page mapping from kernel space or user space. 首先,由于来自内核空间或用户空间的无效页面映射,可能会发生数据中止。 handle_mm_fault is the sub-routine to fix the page table for user space in linux. handle_mm_fault是为Linux中的用户空间修复页表的子例程。 Your design has to cover followings as far as I can understand. 据我所知,您的设计必须涵盖以下内容。

  1. You need a design in place to keep track of the right PID. 您需要适当的设计来跟踪正确的PID。
  2. Have you ever considered, how do you decide which part of vma should rely on demanding 您是否考虑过,如何确定vma的哪一部分应依赖于苛刻的要求
    Page? 页? The whole process VMA or just some parts? VMA的整个过程还是只是某些部分? Linux could use other techniques to create memory mapping for user programs, such as mmap. Linux可以使用其他技术为用户程序创建内存映射,例如mmap。
  3. In order to avoid keeping retry, you have to fix the mapping anyway as CPU will resume execution from aborted position. 为了避免重试,您必须修复映射,因为CPU将从中止位置恢复执行。 If you can't server the mapping from your designated area immediately, a temporary mapping should be created in stead and page out later. 如果您不能立即从指定区域提供地图服务,则应临时创建一个临时地图并在以后调出页面​​。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM