page fault-page exception process

 

Page Faults and Kernel Oops print call process

Phase 1: Determine whether the page fault exception occurs in a kernel thread or an atomic context (interrupts also belong to an atomic context), and if so, execute do_kernel_fault to try to repair or report a segment fault.

Phase 2: Judging whether it is the case of the kernel state accessing the user address space , if yes, judging whether it is the specified three situations, and reporting a segment error if yes.

Phase 3: Enter _do_page_fault, find the vm_area_struct domain where the abnormal address is located, and walk the table (page table walk) to find the PGD PUD ​​PMD corresponding to the address, and finally find the PTE.

Stage 4: Enter handle_pte_fault(), if it is judged that the PTE is empty, it means that the user space is accessing for the first time after applying for a virtual address, and the physical page has not been mapped yet. Execute do_anonymous_page or do_fault according to the page type.

Phase 5: A non-null PTE indicates that a mapping has been established. Determine whether the present bit of the PTE is true. If it is not true, it means that the page is swapping to the disk, and then execute do_swap_page.

Phase 6: Determine whether PTE_PROT_NONE is true, and if it is true, execute do_numa_page to generate page migration.

Stage 7: Determine the type of error. If the type of writing is wrong, then determine the read and write permissions of the PTE. If it is read-only, it means that the page is write-protected, call do_wp_page.

Stage 8: In order to be compatible with ARM32, the Hardware PTE of the ARM32 architecture does not support bits such as DIRTY YOUNG, so it is simulated through software with page fault exceptions.

-------------------------------------------------- ----------------Extensions to other articles---------------------------- --------------------------------------

Since the causes of page faults in kernel space and user space are different, their processing procedures are also different.

For user space, it is necessary to distinguish multiple situations, and the handling of page faults is more complicated.

First of all, the accessed memory address must be legal. The so-called "legal" means that the address must fall within a certain VMA range of the process.

Assuming that the address space of a process is distributed as follows, then address B is legal (good area), and address A is illegal (bad area)

 

Guess you like

Origin blog.csdn.net/y13182588139/article/details/125903900