Query regarding page access protection flags linux kernel
Hello, I am trying to understand the page fault handling and MMU. These are my queries 1) What is the exact difference between the protection flags in vm_area_struct and pte's protection flags of the page. Does the field "pgprot_t vm_page_prot" in vm_area_struct contain the protection flags of all the pages in that vm_area? If so how to set these for individual pages? I have come across this http://marc.info/?l=linux-mm&m=109422600806490 But could not find any answer to this post. 2) Does MMU (x86 arch) check the vm_area prot flags or the page's pte flags to cause the page fault? Please help !! Thanks, Ravali
On Tue, Aug 5, 2014 at 4:49 PM, ravali pullela <rpravali069@gmail.com> wrote:
Hello,
I am trying to understand the page fault handling and MMU. These are my queries
1) What is the exact difference between the protection flags in vm_area_struct and pte's protection flags of the page.
vm_area_struct flags aren't seen by MMU but PTE's protection flags would be seen by MMU for granting access. If there's any mismatch at the PTE's protection flags like write requested but PTE is set to read-only then it'll fault.
Does the field "pgprot_t vm_page_prot" in vm_area_struct contain the protection flags of all the pages in that vm_area? If so how to set these for individual pages?
see handle_pte_fault and /arch/x86/include/asm/pgtable.h for the defs
I have come across this http://marc.info/?l=linux-mm&m=109422600806490 But could not find any answer to this post.
2) Does MMU (x86 arch) check the vm_area prot flags or the page's pte flags to cause the page fault?
MMU will look at PTE's not vm_area_struct. vm_area_struct gets checked later on if there's a fault. See __do_fault or do_page_fault.
Please help !!
Thanks, Ravali
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- ---P.K.S
On Tue, Aug 5, 2014 at 4:19 AM, ravali pullela <rpravali069@gmail.com> wrote:
Hello,
I am trying to understand the page fault handling and MMU. These are my queries
1) What is the exact difference between the protection flags in vm_area_struct and pte's protection flags of the page. Does the field "pgprot_t vm_page_prot" in vm_area_struct contain the protection flags of all the pages in that vm_area? If so how to set these for individual pages?
vm_page_prot contains the protections for the entire range of addresses managed by that vma. If you want to set the protections for individual pages ( by calling mprotect(..) for example), kernel splits the vmas. The rule is that a vma will only manage the range of contiguous addresses that have similar protections. if you set different protections for individual pages, you will end up with one vma per page. If you later the change the protections of contiguous pages to be the same, the kernel will merge the vmas.
I have come across this http://marc.info/?l=linux-mm&m=109422600806490 But could not find any answer to this post.
2) Does MMU (x86 arch) check the vm_area prot flags or the page's pte flags to cause the page fault?
MMU doesn't have access to vm_page_prot. It only looks at the page's pte entry to decide if the page is mapped or not. The reason there are sets of prot flags(1 in vma, 1 in pte entry) is to facilitate features such as copy on write(COW) and on-demand paging. On-demand pages have the present bit off in their corresponding pte entry. So, when a process tries to access an on-demand page for the first time, MMU generates a fault. The page fault handler sees that present bit is off and looks at vm_page_prot. if vm_page_prot has VM_READ or VM_WRITE. If either of these prots are set in vm_page_prot, it sets up the pte entry with present bit set. COW page has the present bit set but the write bit is off. So, a process only has read-only access to the page. When a process attempts to write to that page, page fault is generated. The page fault handler looks at vm_page_prot and if VM_WRITE was set, it allocs a new page, copies the data from old_page to the new page and updates the pte entry with the write bit set. Venkatram Tummala
Please help !!
Thanks, Ravali
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (3)
-
Pranay Srivastava -
ravali pullela -
Venkatram Tummala