remap_file_pages protection support: enhance syscall interface and swapout code
Subsystems (4)
PATCH 12/39 remap_file_pages protection support: enhance syscall interface and swapout code
From: Ingo Molnar <[email protected]>, Paolo 'Blaisorblade' Giarrusso <[email protected]>
This is the "main" patch for the syscall code, containing the core of what was sent by Ingo Molnar, variously reworked.
Differently from his patch, I've *not* added a new syscall, choosing to add a new flag (MAP_NOINHERIT) which the application must specify to get the new behavior (prot != 0 is accepted and prot == 0 means PROT_NONE).
The changes to the page fault handler have been separated, even because that has required considerable amount of effort.
Handle the possibility that remap_file_pages changes protections in various places.
* Enable the 'prot' parameter for shared-writable mappings (the ones which are the primary target for remap_file_pages), without breaking up the vma
* Use pte_file PTE's also when protections don't match, not only when the offset doesn't match; and add set_nonlinear_pte() for this testing
* Save the current protection too when clearing a nonlinear PTE, by replacing pgoff_to_pte() uses with pgoff_prot_to_pte().
* Use the supplied protections on restore and on populate (partially uncomplete, fixed in subsequent patches)
---
linux-2.6.git-paolo/include/linux/pagemap.h | 19 ++++++++++ linux-2.6.git-paolo/mm/fremap.c | 50 +++++++++++++++++----------- linux-2.6.git-paolo/mm/memory.c | 14 ++++--- linux-2.6.git-paolo/mm/rmap.c | 3 - 4 files changed, 60 insertions(+), 26 deletions(-)
include/linux/pagemap.h renamed from include/linux/pagemap.h~rfp-enhance-syscall-and-swapout-code +19 -0
@@ -159,6 +159,25 @@ static inline pgoff_t linear_page_index(return pgoff >> (PAGE_CACHE_SHIFT -PAGE_SHIFT ); } +/*** +* Checks if the PTE is nonlinear, and if yes sets it. +* @vma: the VMA in which @addr is; we don't check if it's VM_NONLINEAR, just +* if this PTE is nonlinear. +* @addr: the addr which @pte refers to. +* @pte: the old PTE value (to read its protections. +* @ptep: the PTE pointer (for setting it). +* @mm: passed to set_pte_at. +* @page: the page which was installed (to read its ->index, i.e. the old +* offset inside the file. +*/ +static inline void set_nonlinear_pte (pte_t pte,pte_t * ptep,struct vm_area_struct *vma,struct mm_struct *mm,struct page * page,unsigned long addr) +{ +pgprot_t pgprot =pte_to_pgprot (pte); +if (linear_page_index (vma, addr) != page->index || +pgprot_val (pgprot) !=pgprot_val (vma->vm_page_prot)) +set_pte_at (mm, addr, ptep,pgoff_prot_to_pte (page->index, pgprot)); +} +extern void FASTCALL (__lock_page (struct page *page));extern void FASTCALL (unlock_page (struct page *page));
mm/fremap.c renamed from mm/fremap.c~rfp-enhance-syscall-and-swapout-code +32 -18
125 lines not on this page · raw message
mm/memory.c renamed from mm/memory.c~rfp-enhance-syscall-and-swapout-code +8 -6
@@ -555,11 +555,11 @@ static void zap_pte_range(struct mmu_gattlb_remove_tlb_entry (tlb, pte, addr);if (unlikely (!page))continue ; -if (unlikely (details) && details->nonlinear_vma - &&linear_page_index (details->nonlinear_vma, - addr) != page->index) -set_pte_at (tlb->mm, addr, pte, -pgoff_to_pte (page->index)); +if (unlikely (details) && details->nonlinear_vma) { +set_nonlinear_pte (ptent, pte, + details->nonlinear_vma, + tlb->mm, page, addr); + }if (pte_dirty (ptent))set_page_dirty (page);if (PageAnon (page))
@@ -1926,6 +1926,7 @@ static int do_file_page(struct mm_struct unsigned long address, int write_access, pte_t *pte, pmd_t *pmd) { unsigned long pgoff; +pgprot_t pgprot;int err;BUG_ON (!vma->vm_ops || !vma->vm_ops->nopage);
@@ -1940,11 +1941,12 @@ static int do_file_page(struct mm_struct } pgoff =pte_to_pgoff (*pte); + pgprot =pte_to_pgprot (*pte);pte_unmap (pte);spin_unlock (&mm->page_table_lock); - err = vma->vm_ops->populate (vma, address &PAGE_MASK ,PAGE_SIZE , vma->vm_page_prot, pgoff,0 ); + err = vma->vm_ops->populate (vma, address &PAGE_MASK ,PAGE_SIZE , pgprot, pgoff,0 );if (err == -ENOMEM )return VM_FAULT_OOM ;if (err)
mm/rmap.c renamed from mm/rmap.c~rfp-enhance-syscall-and-swapout-code +1 -2
@@ -660,8 +660,7 @@ static void try_to_unmap_cluster(unsigne pteval =ptep_clear_flush (vma, address, pte);/* If nonlinear, store the file page offset in the pte. */ -if (page->index !=linear_page_index (vma, address)) -set_pte_at (mm, address, pte,pgoff_to_pte (page->index)); +set_nonlinear_pte (pteval, pte, vma, mm, page, address);/* Move the dirty bit to the physical page now the pte is gone. */ if (pte_dirty (pteval))
_