After this documentation was released in July 2003, I was approached
by Prentice Hall and asked to write a book on the Linux VM under the Bruce Peren's Open Book Series.
The book is available and called simply "Understanding The Linux Virtual
Memory Manager". There is a lot of additional material in the book that is
not available here, including details on later 2.4 kernels, introductions
to 2.6, a whole new chapter on the shared memory filesystem, coverage of TLB
management, a lot more code commentary, countless other additions and
clarifications and a CD with lots of cool stuff on it. This material (although
now dated and lacking in comparison to the book) will remain available
although I obviously encourge you to buy the book from your favourite book
store :-) . As the book is under the Bruce Perens Open Book Series, it will
be available 90 days after appearing on the book shelves which means it
is not available right now. When it is available, it will be downloadable
from http://www.phptr.com/perens
so check there for more information.
To be fully clear, this webpage is not the actual book.
Next: 5.6 Page Faulting
Up: 5. Process Address Space
Previous: 5.4 Memory Regions
  Contents
  Index
5.5 Exception Handling
A very important part of VM is how exceptions related to bad kernel address
references are caught 5.9 which are not a result of a kernel
bug5.10. This section does not
cover the exceptions that are raised with errors such as divide by zero,
we are only concerned with the exception raised as the result of a page
fault. There are two situations where a bad reference may occur. The first
is where a process sends an invalid pointer to the kernel via a system call
which the kernel must be able to safely trap as the only check made initially
is that the address is below PAGE_OFFSET. The second is where
the kernel uses copy_from_user() or copy_to_user()
to read or write data from userspace.
At compile time, the linker creates an exception table in
the __ex_table section of the kernel code segment
which starts at __start___ex_table and ends
at __stop___ex_table. Each entry is of type
exception_table_entry which is a pair consisting of an execution
point and a fixup routine. When an exception occurs that the page fault handler
cannot manage, it calls search_exception_table() to see if a
fixup routine has been provided for an error at the faulting instruction. If
module support is compiled, each module's exception table will also be searched.
If the address of the current exception is found in the table, the
corresponding location of the fixup code is returned and executed. We will
see in Section 5.7 how this is used to trap
bad reads and writes to userspace.
Footnotes
- ... caught5.9
- Many thanks go to Ingo Oeser for clearing up
the details of how this is implemented.
- ...
bug5.10
- Of course bad references due to kernel bugs should rightfully
cause the system to have a minor fit.
Next: 5.6 Page Faulting
Up: 5. Process Address Space
Previous: 5.4 Memory Regions
  Contents
  Index
Mel
2004-02-15