As per pgtable-2-level.h, ARM Linux has two version of PTE; The Linux PTE and H/W PTE. Linux PTE are stored on below a offset of 1024 bytes.
When handling page fault in handle_pte_fault
various function like pte_file
, pte_mkdirty
, pte_mkyoung
, get invoke with the version H/W PTE.
But actually ARM H/W does not support the dirty, accessed and file bit in its PTE.
My question is how does it check the dirty, accessed, file bit of a page on H/W PTE? Ideally it should check those bit on Linux PTE which are stored below an offset of 1024 bytes?
TL;DR - they are emulated by taking a page fault on initial accesses.
The answers are given in pgtable-2-level.h,
To take the dirty case, the initial MMU mappings for page are marked read-only. When a process writes to it, a page fault is generated. This is the
handle_pte_fault
referenced and the main code is in fault.c asdo_page_fault
and will call the generichandle_mm_fault
which eventually ends athandle_pte_fault
. You can see the code,So the Linux generic code will examine the permission of the page, see it is suppose to be writeable and call the
pte_mkdirty
to mark the page as dirty; the whole process is kicked off or emulated through the fault handler. After the page is marked dirty in the Linux PTE, the ARM PTE is marked as writeable so subsequent writes do not cause a fault.accessed is identical only both read and write will initially fault. A file bit is also completely unmapped and when a fault occurs, the Linux PTE is consulted to see if it is backed by a file or is it a completely unmapped page fault.
After the hardware table is updated with new permissions and book keeping is done, the user mode program is restarted at the faulting instruction and it would not notice the difference, besides the time interval to handle the fault.
ARM Linux uses 4k pages and the ARM 2nd level page tables are 1k in size (256 entries * 4bytes). From the pgtable-2-level.h comments,
In order to use the full 4K page, the PTE entries are structured like,
Four 1k items for a full 4k page. These collections of pages must be managed per process to give each a unique view of memory and some information is shared in order to conserve real RAM. The function
cpu_set_pte_ext
is used to change the physical ARM entries. As each ARM CPU revision uses slightly different tables structures and features, there is an entry in the processor function table that points to an assembler routine. For instance,cpu_v7_set_pte_ext
is the ARMv7 or typical original Cortex CPU implementation. This routine is responsible for examining the Linux flags and updating the hardware bits accordingly. As can be seen, ther3
is written topte+2048
(offset from Linux PTE to hardware PTE) at the end of this routine. The assembler macroarmv3_set_pte_ext
in proc-marcos.S is used by many of the older CPU variants.See: Tim's notes on ARM MM
Page table entry (PTE) descriptor in Linux kernel for ARM