Re: [patch 2/5] Reinstate ZERO_PAGE optimization in get_user_pages() and fix XIP

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Hugh Dickins <hugh@...>
Cc: Jeff Chua <jeff.chua.linux@...>, Greg KH <gregkh@...>, <linux-kernel@...>, <stable@...>, Justin Forbes <jmforbes@...>, Zwane Mwaikambo <zwane@...>, Theodore Ts'o <tytso@...>, Randy Dunlap <rdunlap@...>, Dave Jones <davej@...>, Chuck Wolber <chuckw@...>, Chris Wedgwood <reviews@...>, Michael Krufky <mkrufky@...>, Chuck Ebbert <cebbert@...>, Domenico Andreoli <cavokz@...>, Willy Tarreau <w@...>, Rodrigo Rubira Branco <rbranco@...>, <akpm@...>, <alan@...>, Oleg Nesterov <oleg@...>, Nick Piggin <npiggin@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, Ingo Molnar <mingo@...>, Roland McGrath <roland@...>
Date: Monday, June 23, 2008 - 12:39 pm

On Mon, 23 Jun 2008, Hugh Dickins wrote:


The problem is that the old code said:

 - we can use FOLL_ANON, assuming that the vma has no vm_ops, or has no 
   "fault" callback.

That was funcamentally broken. Because you can have a "nopfn" callback. 
But it's hard to notice, since the whole FOLL_ANON code only _used_ to 
trigger if a whole page table was missing.

The VM_LOCKED test was just crazy, but I doubt it was the cause of the 
bug.


That's still crazy. make_pages_present() already does:

	write = (vma->vm_flags & VM_WRITE) != 0;

and passes that in to "get_user_pages()". So for a writable mapping, we'll 
elide the FOLL_ANON case anyway, and for a read-only mapping we should 
have used ZERO_PAGE. Damn. Oh, well.

We can certainly re-instate the insane behaviour for mlock(). Not that we 
historically used to - we used to just map in ZERO_PAGE.


So here's a third patch to test. It removes the VM_SHARED thing just to 
get us closer to the original code (and because do_no_page() didn't do it 
historically, so let's not do it either), and it re-instates the insane 
VM_LOCKED test with a comment.

Jeff, does this still work with vmware?

		Linus

---
 mm/memory.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 9aefaae..a2ce28d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1045,6 +1045,23 @@ no_page_table:
 	return page;
 }
 
+/* Can we do the FOLL_ANON optimization? */
+static inline int use_zero_page(struct vm_area_struct *vma)
+{
+	/*
+	 * We don't want to optimize FOLL_ANON for make_pages_present()
+	 * when it tries to page in a VM_LOCKED region.
+	 */
+	if (vma->vm_flags & VM_LOCKED)
+		return 0;
+	/*
+	 * And if we have a fault or a nopfn routine, it's not an
+	 * anonymous region.
+	 */
+	return !vma->vm_ops ||
+		(!vma->vm_ops->fault && !vma->vm_ops->nopfn);
+}
+
 int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		unsigned long start, int len, int write, int force,
 		struct page **pages, struct vm_area_struct **vmas)
@@ -1119,8 +1136,7 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		foll_flags = FOLL_TOUCH;
 		if (pages)
 			foll_flags |= FOLL_GET;
-		if (!write && !(vma->vm_flags & VM_LOCKED) &&
-		    (!vma->vm_ops || !vma->vm_ops->fault))
+		if (!write && use_zero_page(vma))
 			foll_flags |= FOLL_ANON;
 
 		do {
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 0/5] 2.6.25-stable review, Greg KH, (Sun Jun 22, 3:01 pm)
Re: [patch 0/5] 2.6.25-stable review, S.Çağlar, (Mon Jun 23, 7:19 am)
Re: [stable] [patch 0/5] 2.6.25-stable review, Greg KH, (Mon Jun 23, 3:30 pm)
Re: [patch 2/5] Reinstate ZERO_PAGE optimization in get_user..., Linus Torvalds, (Mon Jun 23, 12:39 pm)
[patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Greg KH, (Sun Jun 22, 3:01 pm)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Johannes Weiner, (Sun Jun 22, 4:22 pm)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Linus Torvalds, (Sun Jun 22, 4:36 pm)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Ingo Molnar, (Mon Jun 23, 4:09 am)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Bernhard Walle, (Mon Jun 23, 6:33 am)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Ingo Molnar, (Mon Jun 23, 6:53 am)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Bernhard Walle, (Mon Jun 23, 9:21 am)
Re: [patch 4/5] x86: use BOOTMEM_EXCLUSIVE on 32-bit, Adrian Bunk, (Sun Jun 22, 4:36 pm)