Skip to contentSkip to conversation

remap_file_pages protection support: avoid redundant pte_file PTE's

PATCH In review [email protected] 1 participant 1 message Aug 12, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 35/39 remap_file_pages protection support: avoid redundant pte_file PTE's

From: Paolo 'Blaisorblade' Giarrusso <[email protected]>

For linear VMA's, there is no need to install pte_file PTEs to remember the offset. We could probably go as far as checking directly the address and protection like in include/linux/pagemap.h:set_nonlinear_pte(), instead of vma->vm_flags. Also add some warnings on the path which used to cope with such PTE's.

Untested yet.

---

 linux-2.6.git-paolo/mm/fremap.c |   12 ++++++------
 linux-2.6.git-paolo/mm/memory.c |    5 +++++
 2 files changed, 11 insertions(+), 6 deletions(-)
mm/fremap.c renamed from mm/fremap.c~rfp-linear-optim-v3 +6 -6
diff -puN mm/fremap.c~rfp-linear-optim-v3 mm/fremap.c
@@ -125,6 +125,12 @@ int install_file_pte(struct mm_struct *m
 
  	BUG_ON(!uniform && !(vma->vm_flags & VM_SHARED));
 
+	/* We're being called by mmap(MAP_NONBLOCK|MAP_POPULATE) on an uniform
+	 * VMA. So don't need to take the lock, and to install a PTE for the
+	 * page we'd fault in anyway. */
+	if (uniform)
+		return 0;
+
 	pgd = pgd_offset(mm, addr);
 	spin_lock(&mm->page_table_lock);
 	
@@ -139,12 +145,6 @@ int install_file_pte(struct mm_struct *m
 	pte = pte_alloc_map(mm, pmd, addr);
 	if (!pte)
 		goto err_unlock;
-	/*
-	 * Skip uniform non-existent ptes:
-	 */
-	err = 0;
-	if (uniform && pte_none(*pte))
-		goto err_unlock;
 
 	zap_pte(mm, vma, addr, pte);
 
mm/memory.c renamed from mm/memory.c~rfp-linear-optim-v3 +5 -0
diff -puN mm/memory.c~rfp-linear-optim-v3 mm/memory.c
@@ -1969,9 +1969,14 @@ static int do_file_page(struct mm_struct
 	/*
 	 * Fall back to the linear mapping if the fs does not support
 	 * ->populate; in this case do the protection checks.
+	 * Could have been installed by install_file_pte, for a MAP_NONBLOCK
+	 * pagetable population.
 	 */
 	if (!vma->vm_ops->populate ||
 			((access_mask & VM_WRITE) && !(vma->vm_flags & VM_SHARED))) {
+		/* remap_file_pages should disallow this, now that
+		 * install_file_pte skips linear ones. */
+		WARN_ON(1);
 		/* We're behaving as if pte_file was cleared, so check
 		 * protections like in handle_pte_fault. */
 		if (check_perms(vma, access_mask))

_