2014-02-19 15:28:43

by Hu Yaohui

[permalink] [raw]
Subject: How pte_mkspecial makes zero-page COW on x86 ARCH

Hi All,
I read the code in do_anonymous_page of the latest linux kernel.
I am pretty confused how pte_mkspecial to make the zero-page COW on
x86 architecture
<code>
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;
}
......
}
</code>
In the previous linux kernel, this is done by pte_wrprotect to make page COW.
Thanks for your time!

Best Wishes,
Yaohui