Vm_flags vs vm_page_prot

I work with linux kernel 2.6.38 and ask a question about two fields vm_area_struct , vm_flags and vm_page_prot . If I can close anonymous memory so that it can be read and written, and then I print two fields of the created vm_area_struct, I see that the lower 8 bits of vm_flags are 0x73, and the lower 8 bits of vm_page_prot are 0x25. I run x86 32-bit and my constants

 VM_READ=0x01 VM_WRITE=0x02 VM_EXEC=0x04 

Thus, it seems that vm_flags says that the memory is read / write, but vm_page_prot says that it is read-only (the executable flag does not make sense on x86). I understand that vm_page_prot should reflect the protection of the page page table entries in the VM area. When I switch to read / write memory in the mmaped area in user space, the page crash mechanism works correctly by setting the PTE of the respective pages. Some pages (if I only read them) are displayed on a special zero page frame when the PTE is set to read-only, while other pages that are written have a PTE for reading / writing. This is the expected behavior ... in fact, from mm / memory.c:

 static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, pte_t *page_table, pmd_t *pmd, unsigned int flags) { ... entry = pte_mkspecial(pfn_pte(my_zero_pfn(address), vma->vm_page_prot)); ... } 

My question is what vm_page_prot defines. I assume that vm_page_prot is somehow the most restrictive combination (intersection) of all page permissions in the VM area, while vm_flags actually describes the true intentions of using memory.

Does anyone have any good articles on what are the exact goals / differences of the two fields?

+4
source share
1 answer

Note the C types of these two fields. vm_page_prot type pgprot_t , which is an arch level data type, which means that it can be applied directly to the PTE of the underlying architecture. On a 32-bit x86, this field stores the contents of the corresponding security bits for PTE VMA. vm_flags , in contrast, is an arc-independent field whose bits are defined in linux/mm.h There are many VM_ * bits, and they only apply strongly to the simple READ, WRITE, and EXEC flags.

So, it seems to me that vm_page_prot is a form of cached conversion from vm_flags , which stores the corresponding protection bits for the underlying architecture. Note that in many areas where PTE is configured in VMA, pgprot_t used almost directly.

+6
source

Source: https://habr.com/ru/post/1379974/


All Articles