Query regarding page access protection flags linux kernel
Venkatram Tummala
venkatram867 at gmail.com
Mon Aug 18 04:56:18 EDT 2014
On Tue, Aug 5, 2014 at 4:19 AM, ravali pullela <rpravali069 at 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 at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140818/e1a2b8c2/attachment.html
More information about the Kernelnewbies
mailing list