Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


4.11.4 Getting Nonlinear Mappings


Page fault handling for nonlinear mappings is much shorter than when the methods described above are
used:

mm/memory.c
static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, pte_t *page_table, pmd_t *pmd,
int write_access, pte_t orig_pte)
{
...
pgoff = pte_to_pgoff(orig_pte);
return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
}

Since the faulting address is not linearly associated with the contents of the mapped file, the desired posi-
tion must be obtained from the information in the PTE that was previously encoded withpgoff_to_pte.
Now comes the time to put this information to use:pte_to_pgoffanalyzes the page table entry and
obtains the desired page-sized offset into the file.

Once the address within the file is known, reading in the required data can be pursued as for regular
page faults. The kernel thus hands off the work to the previously discussed function__do_page_fault
and is done.

4.12 Kernel Page Faults


When kernel address space is accessed, page faultscan be triggered by various conditions as described
below.

❑ A programming error in the kernel has caused an incorrect address to be accessed — this is a
genuine bug. Of course, this should never happen in stable versions^20 but does occur occasion-
ally in developer versions.
❑ The kernel accesses an invalid address passed as a system call parameter from userspace.
❑ The page fault was triggered by access to an area allocated usingvmalloc.

The first two conditions are genuine errors against which the kernel must guard by performing additional
checks. Thevmallocsituation is a legitimate reason for a page fault that must be corrected. Modifications
in thevmallocaddress space are not transmitted to the page tables of a process until a corresponding
page fault has occurred; the appropriate access information must be copied from the master page table.
Although this is not a difficult operation, it is strongly architecture-dependent, so I won’t discuss it here.

Theexception fixupmechanism is a last resort when handling page faults not due to accessingvmalloc
area. At some points, the kernel makes preparations for intercepting incorrect accesses that are made
for a legitimate reason — for example, when copying address data from userspace addresses passed as
system call parameters.

(^20) In fact, errors of this kind very rarely occur because — as you might have already noted — Linux is an extremely stable system...

Free download pdf