Search code examples
linuxlinux-kernelvirtual-memorykernel-mode

Kernel Mode - Physical Addresses or Virtual Addresses?


Does a code that runs on kernel mode uses Physical Addresses or Virtual Addresses?

If it is virtual, which translation tables does it use? are they updated differently with comparison to user-mode tables?

Thanks


Solution

  • The answer is that kernel mode code uses a mixture of virtual, logical, and physical addressing. How much of each is used depends upon the underlying hardware and operating system.

    There has to be some physical addressing in the kernel. Otherwise, there would be the chicken and egg problem of how does one set up logical addressing without knowing physical addresses to map to.

    The ideal would be for the system to only use physical addresses for system registers.

    The logical/virtual address distinction is important as well. It is possible for some parts of the kernel address space to be pageable (virtual memory). Others parts could be nonpageable (logical memory only).

    Kernel mode address translation is very hardware dependent. Some systems make user mode page tables pageable themselves. In such systems, there is two levels of address translation (virtual addresses for the page table and virtual addresses using the page table). The underlying hardware defines specific addresses ranges as kernel addresses. Other systems allow the system (kernel) address space to be defined entirely in software. In such systems, kernel and user address translation is pretty much the same.