0

while I was thinking of making a networked paging (request the faulting page from remote node), I got this question:

First, let's consider the following steps:

1) a user-space program tries to access at memory X.

2) MMU walks the page table to find the physical address of X.

3) while walking the page table, it notice that the page table entry is invalid.

4) CPU traps and is catched by the Linux trap vector. (In ARM case, but I think x86 is also the same, right?)

5) At this point, I can retrieve the proper data from remote node, copy into some physical address and map it in page table.

6) Here goes the question: After this point, would the program that has page fault at X safely read the data?, Then, does it mean MMU or CPU somehow remembers the page faulting page table entry and return to that entry and resume the walking of page table?

If any of the steps are not right, please enlighten me.

jaeyong
  • 8,951
  • 14
  • 50
  • 63
  • 1
    Application-level user programs and kernel are not the same thing. The kernel does handle page fault and SIGSEGV from user programs. Read [virtual memory](http://en.wikipedia.org/wiki/Virtual_memory), [virtual address space](http://en.wikipedia.org/wiki/Virtual_address_space), [MMU](http://en.wikipedia.org/wiki/Memory_management_unit), [Linux kernel](http://en.wikipedia.org/wiki/Linux_kernel) wikipages. Kernel code should not page-fault. – Basile Starynkevitch Aug 09 '13 at 11:33
  • Oops right. Kernel code should not page-fault. What I meant is user space application. Question fixed. – jaeyong Aug 09 '13 at 11:41
  • The kernel does the right job to either send a `SIGSEGV` to the application process, or to have the data available in RAM. – Basile Starynkevitch Aug 09 '13 at 11:43
  • The question is while kernel is doing the job, application stops at the point of reading variable x. After the kernel does the job, does the application's PC starts at "reading variable x" (such as asm ld r0, [x])? or some kind of internal state of instruction is stored somewhere and starts at MMU page table walking? – jaeyong Aug 09 '13 at 11:49
  • It could be architecture specific. On x86 the same machine instruction gets restarted. In particular, a `SIGSEGV` handler which does not change the address space or the faulting address will be infinitely repeated. – Basile Starynkevitch Aug 09 '13 at 11:51
  • Thanks Basile, if I want to know such kind of behavior, could you give me some references or websites? – jaeyong Aug 10 '13 at 04:15

2 Answers2

0

Data abort handler just assigns to the pc the same value as before the data abort handling started, and instruction gets executed again, with right data in place, so data abort won't happen again.

Michael Pankov
  • 3,581
  • 2
  • 23
  • 31
0

The solution is tricky and non-portable.

You can get the values of the CPU registers, when the segmentation fault occurred, from a signal handler (link: http://man7.org/linux/man-pages/man2/sigaction.2.html). You need to analyse these to decide whether you can fix the situation. First you need to check that the instruction pointer is valid. Then, you need to check that the faulty address lies in a valid range. Then, you need to map memory for the non existent pages with mmap() system call. Then, you need to copy the required data to these pages. After the signal handler returns, the process will resume from where the segmentation fault had occurred.

Sanjib Pradhan
  • 108
  • 1
  • 8