Initialization of Paging

paging_init is responsible for setting up the page tables that can be used only by the kernel and are not accessible in userspace. This has far-reaching effects on the way in which access to memory is regulated between normal applications and the kernel itself. It is therefore important to explain the purpose of the function before looking closely at its implementation.

As noted in Chapter 1, on IA-32 systems the kernel typically divides the total available virtual address space of 4 GiB in a ratio of 3 : 1. The lower 3 GiB are available for user-mode applications, and the upper gigabyte is reserved exclusively for the kernel. Whereas the current system context is irrelevant when assigning the virtual address space of the kernel, each process has its own specific address space.

The major reasons for this division are as follows:

□ When execution of a user application switches to kernel mode (this always happens when, e.g., a system call is used or a periodic timer interrupt is generated), the kernel must be embedded in a reliable environment. It is therefore essential to assign part of the address space exclusively to the kernel.

□ The physical pages are mapped to the start of the kernel address space so that the kernel can access them directly without the need for complicated page table operations.

If all physical pages were mapped into the address space accessible to userspace processes, this would lead to serious security problems if several applications were running on the system. Each application would then be able to read and modify the memory areas of other processes in physical RAM. Obviously this must be prevented at all costs.

While the virtual address portion employed for userland processes changes with every task switch, the kernel portion is always the same. The situation is summarized in Figure 3-14.

Physical memory

Physical memory

Task switch

Figure 3-14: Connection between virtual and physical address space on IA-32 processors.

Task switch

Figure 3-14: Connection between virtual and physical address space on IA-32 processors.

+1 0

Post a comment