do_anonymous_page cow

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
loki2441
Posts: 7
Joined: Sun Jan 05, 2014 9:37 pm

do_anonymous_page cow

Post by loki2441 »

Hi,
I have a question related to read anonymous memory area.
In Linux kernel, when first read anonymous area, a page fault will happen which will call do_anonymous_page
It will allocate a zero-page to delay the real allocation. This page table entry should be marked write-protected.
When the page is written next time, a do_wp_page will be called to handle this situation.

Code: Select all

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)
{
.....
        /* Use the zero-page for reads */
        if (!(flags & FAULT_FLAG_WRITE)) {
                entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
                                                vma->vm_page_prot));
                page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
                if (!pte_none(*page_table))
                        goto unlock;
                goto setpte;
        }
......
}
I am not sure how pte_mkspecial will make the page entry as COW.
since in the old version, the entry is created by following function:

Code: Select all

entry = pte_wrprotect(mk_pte(virt_to_page(empty_zero_page),
                                 vma->vm_page_prot));
I don't know whether this is caused by the the x86 architecture change.
Thanks for your time!

Best Wishes,
Yaohui Hu
Post Reply