linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area
@ 2007-04-24  5:33 Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 1/12] get_unmapped_area handles MAP_FIXED on powerpc Benjamin Herrenschmidt
                   ` (11 more replies)
  0 siblings, 12 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

This is a "first step" as there are still cleanups to be done in various
areas touched by that code but I think it's probably good to go as is and
at least enables me to implement what I need for PowerPC.

(Andrew, this is also candidate for 2.6.22 since I haven't had any real
objection, mostly suggestion for improving further, which I'll try to
do later, and I have further powerpc patches that rely on this).

The current get_unmapped_area code calls the f_ops->get_unmapped_area or
the arch one (via the mm) only when MAP_FIXED is not passed. That makes
it impossible for archs to impose proper constraints on regions of the
virtual address space. To work around that, get_unmapped_area() then
calls some hugetlbfs specific hacks.

This cause several problems, among others:

 - It makes it impossible for a driver or filesystem to do the same thing
that hugetlbfs does (for example, to allow a driver to use larger page
sizes to map external hardware) if that requires applying a constraint
on the addresses (constraining that mapping in certain regions and other
mappings out of those regions).

 - Some archs like arm, mips, sparc, sparc64, sh and sh64 already want
MAP_FIXED to be passed down in order to deal with aliasing issues.
The code is there to handle it... but is never called.

This serie of patches moves the logic to handle MAP_FIXED down to the
various arch/driver get_unmapped_area() implementations, and then changes
the generic code to always call them. The hugetlbfs hacks then disappear
from the generic code.

Since I need to do some special 64K pages mappings for SPEs on cell, I need
to work around the first problem at least. I have further patches thus
implementing a "slices" layer that handles multiple page sizes through
slices of the address space for use by hugetlbfs, the SPE code, and possibly
others, but it requires that serie of patches first/

There is still a potential (but not practical) issue due to the fact that
filesystems/drivers implemeting g_u_a will effectively bypass all arch
checks. This is not an issue in practice as the only filesystems/drivers
using that hook are doing so for arch specific purposes in the first place.

There is also a problem with mremap that will completely bypass all arch
checks. I'll try to address that separately, I'm not 100% certain yet how,
possibly by making it not work when the vma has a file whose f_ops has a
get_unmapped_area callback, and by making it use is_hugepage_only_range()
before expanding into a new area.

Also, I want to turn is_hugepage_only_range() into a more generic
is_normal_page_range() as that's really what it will end up meaning
when used in stack grow, brk grow and mremap.

None of the above "issues" however are introduced by this patch, they are
already there, so I think the patch can go ini for 2.6.22.

(Patch is against Linus current git, I'll give a go at -mm asap)

Cheers,
Ben.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/12] get_unmapped_area handles MAP_FIXED on powerpc
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 2/12] get_unmapped_area handles MAP_FIXED on alpha Benjamin Herrenschmidt
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in powerpc's arch_get_unmapped_area() in all 3
implementations of it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 arch/powerpc/mm/hugetlbpage.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Index: linux-cell/arch/powerpc/mm/hugetlbpage.c
===================================================================
--- linux-cell.orig/arch/powerpc/mm/hugetlbpage.c	2007-04-24 15:10:17.000000000 +1000
+++ linux-cell/arch/powerpc/mm/hugetlbpage.c	2007-04-24 15:28:11.000000000 +1000
@@ -566,6 +566,13 @@ unsigned long arch_get_unmapped_area(str
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	/* handle fixed mapping: prevent overlap with huge pages */
+	if (flags & MAP_FIXED) {
+		if (is_hugepage_only_range(mm, addr, len))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (addr) {
 		addr = PAGE_ALIGN(addr);
 		vma = find_vma(mm, addr);
@@ -641,6 +648,13 @@ arch_get_unmapped_area_topdown(struct fi
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	/* handle fixed mapping: prevent overlap with huge pages */
+	if (flags & MAP_FIXED) {
+		if (is_hugepage_only_range(mm, addr, len))
+			return -EINVAL;
+		return addr;
+	}
+
 	/* dont allow allocations above current base */
 	if (mm->free_area_cache > base)
 		mm->free_area_cache = base;
@@ -823,6 +837,13 @@ unsigned long hugetlb_get_unmapped_area(
 	/* Paranoia, caller should have dealt with this */
 	BUG_ON((addr + len)  < addr);
 
+	/* Handle MAP_FIXED */
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (test_thread_flag(TIF_32BIT)) {
 		curareas = current->mm->context.low_htlb_areas;
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/12] get_unmapped_area handles MAP_FIXED on alpha
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 1/12] get_unmapped_area handles MAP_FIXED on powerpc Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 4/12] get_unmapped_area handles MAP_FIXED on frv Benjamin Herrenschmidt
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in alpha's arch_get_unmapped_area(), simple case, just
return the address as passed in

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/alpha/kernel/osf_sys.c |    3 +++
 1 file changed, 3 insertions(+)

Index: linux-cell/arch/alpha/kernel/osf_sys.c
===================================================================
--- linux-cell.orig/arch/alpha/kernel/osf_sys.c	2007-03-22 14:58:33.000000000 +1100
+++ linux-cell/arch/alpha/kernel/osf_sys.c	2007-03-22 14:58:44.000000000 +1100
@@ -1267,6 +1267,9 @@ arch_get_unmapped_area(struct file *filp
 	if (len > limit)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED)
+		return addr;
+
 	/* First, see if the given suggestion fits.
 
 	   The OSF/1 loader (/sbin/loader) relies on us returning an

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (2 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 4/12] get_unmapped_area handles MAP_FIXED on frv Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-25  8:27   ` Russell King
  2007-04-24  5:33 ` [PATCH 5/12] get_unmapped_area handles MAP_FIXED on i386 Benjamin Herrenschmidt
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

ARM already had a case for MAP_FIXED in arch_get_unmapped_area() though
it was not called before. Fix the comment to reflect that it will now
be called.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/arm/mm/mmap.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: linux-cell/arch/arm/mm/mmap.c
===================================================================
--- linux-cell.orig/arch/arm/mm/mmap.c	2007-03-22 14:59:51.000000000 +1100
+++ linux-cell/arch/arm/mm/mmap.c	2007-03-22 15:00:01.000000000 +1100
@@ -49,8 +49,7 @@ arch_get_unmapped_area(struct file *filp
 #endif
 
 	/*
-	 * We should enforce the MAP_FIXED case.  However, currently
-	 * the generic kernel code doesn't allow us to handle this.
+	 * We enforce the MAP_FIXED case.
 	 */
 	if (flags & MAP_FIXED) {
 		if (aliasing && flags & MAP_SHARED && addr & (SHMLBA - 1))

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 4/12] get_unmapped_area handles MAP_FIXED on frv
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 1/12] get_unmapped_area handles MAP_FIXED on powerpc Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 2/12] get_unmapped_area handles MAP_FIXED on alpha Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm Benjamin Herrenschmidt
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in arch_get_unmapped_area on frv. Trivial case, just
return the address.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/frv/mm/elf-fdpic.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux-cell/arch/frv/mm/elf-fdpic.c
===================================================================
--- linux-cell.orig/arch/frv/mm/elf-fdpic.c	2007-03-22 15:00:50.000000000 +1100
+++ linux-cell/arch/frv/mm/elf-fdpic.c	2007-03-22 15:01:06.000000000 +1100
@@ -64,6 +64,10 @@ unsigned long arch_get_unmapped_area(str
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	/* handle MAP_FIXED */
+	if (flags & MAP_FIXED)
+		return addr;
+
 	/* only honour a hint if we're not going to clobber something doing so */
 	if (addr) {
 		addr = PAGE_ALIGN(addr);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 6/12] get_unmapped_area handles MAP_FIXED on ia64
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (4 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 5/12] get_unmapped_area handles MAP_FIXED on i386 Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 7/12] get_unmapped_area handles MAP_FIXED on parisc Benjamin Herrenschmidt
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in ia64 arch_get_unmapped_area and
hugetlb_get_unmapped_area(), just call prepare_hugepage_range
in the later and is_hugepage_only_range() in the former.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 arch/ia64/kernel/sys_ia64.c |    7 +++++++
 arch/ia64/mm/hugetlbpage.c  |    8 ++++++++
 2 files changed, 15 insertions(+)

Index: linux-cell/arch/ia64/kernel/sys_ia64.c
===================================================================
--- linux-cell.orig/arch/ia64/kernel/sys_ia64.c	2007-03-22 15:10:45.000000000 +1100
+++ linux-cell/arch/ia64/kernel/sys_ia64.c	2007-03-22 15:10:47.000000000 +1100
@@ -33,6 +33,13 @@ arch_get_unmapped_area (struct file *fil
 	if (len > RGN_MAP_LIMIT)
 		return -ENOMEM;
 
+	/* handle fixed mapping: prevent overlap with huge pages */
+	if (flags & MAP_FIXED) {
+		if (is_hugepage_only_range(mm, addr, len))
+			return -EINVAL;
+		return addr;
+	}
+
 #ifdef CONFIG_HUGETLB_PAGE
 	if (REGION_NUMBER(addr) == RGN_HPAGE)
 		addr = 0;
Index: linux-cell/arch/ia64/mm/hugetlbpage.c
===================================================================
--- linux-cell.orig/arch/ia64/mm/hugetlbpage.c	2007-03-22 15:12:32.000000000 +1100
+++ linux-cell/arch/ia64/mm/hugetlbpage.c	2007-03-22 15:12:39.000000000 +1100
@@ -148,6 +148,14 @@ unsigned long hugetlb_get_unmapped_area(
 		return -ENOMEM;
 	if (len & ~HPAGE_MASK)
 		return -EINVAL;
+
+	/* Handle MAP_FIXED */
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	/* This code assumes that RGN_HPAGE != 0. */
 	if ((REGION_NUMBER(addr) != RGN_HPAGE) || (addr & (HPAGE_SIZE - 1)))
 		addr = HPAGE_REGION_BASE;
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 5/12] get_unmapped_area handles MAP_FIXED on i386
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (3 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 6/12] get_unmapped_area handles MAP_FIXED on ia64 Benjamin Herrenschmidt
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in i386 hugetlb_get_unmapped_area(), just call
prepare_hugepage_range.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 arch/i386/mm/hugetlbpage.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-cell/arch/i386/mm/hugetlbpage.c
===================================================================
--- linux-cell.orig/arch/i386/mm/hugetlbpage.c	2007-03-22 16:08:12.000000000 +1100
+++ linux-cell/arch/i386/mm/hugetlbpage.c	2007-03-22 16:14:19.000000000 +1100
@@ -367,6 +367,12 @@ hugetlb_get_unmapped_area(struct file *f
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (addr) {
 		addr = ALIGN(addr, HPAGE_SIZE);
 		vma = find_vma(mm, addr);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (6 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 7/12] get_unmapped_area handles MAP_FIXED on parisc Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 9/12] get_unmapped_area handles MAP_FIXED on x86_64 Benjamin Herrenschmidt
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in hugetlb_get_unmapped_area on sparc64
by just using prepare_hugepage_range()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 arch/sparc64/mm/hugetlbpage.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-cell/arch/sparc64/mm/hugetlbpage.c
===================================================================
--- linux-cell.orig/arch/sparc64/mm/hugetlbpage.c	2007-03-22 16:12:57.000000000 +1100
+++ linux-cell/arch/sparc64/mm/hugetlbpage.c	2007-03-22 16:15:33.000000000 +1100
@@ -175,6 +175,12 @@ hugetlb_get_unmapped_area(struct file *f
 	if (len > task_size)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (addr) {
 		addr = ALIGN(addr, HPAGE_SIZE);
 		vma = find_vma(mm, addr);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 7/12] get_unmapped_area handles MAP_FIXED on parisc
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (5 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 6/12] get_unmapped_area handles MAP_FIXED on ia64 Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64 Benjamin Herrenschmidt
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in parisc arch_get_unmapped_area(), just return the
address. We might want to also check for possible cache aliasing
issues now that we get called in that case (like ARM or MIPS),
leave a comment for the maintainers to pick up.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/parisc/kernel/sys_parisc.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: linux-cell/arch/parisc/kernel/sys_parisc.c
===================================================================
--- linux-cell.orig/arch/parisc/kernel/sys_parisc.c	2007-03-22 15:28:05.000000000 +1100
+++ linux-cell/arch/parisc/kernel/sys_parisc.c	2007-03-22 15:29:08.000000000 +1100
@@ -106,6 +106,11 @@ unsigned long arch_get_unmapped_area(str
 {
 	if (len > TASK_SIZE)
 		return -ENOMEM;
+	/* Might want to check for cache aliasing issues for MAP_FIXED case
+	 * like ARM or MIPS ??? --BenH.
+	 */
+	if (flags & MAP_FIXED)
+		return addr;
 	if (!addr)
 		addr = TASK_UNMAPPED_BASE;
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 9/12] get_unmapped_area handles MAP_FIXED on x86_64
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (7 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64 Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 10/12] get_unmapped_area handles MAP_FIXED in hugetlbfs Benjamin Herrenschmidt
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Handle MAP_FIXED in x86_64 arch_get_unmapped_area(), simple case, just
return the address as passed in

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/x86_64/kernel/sys_x86_64.c |    3 +++
 1 file changed, 3 insertions(+)

Index: linux-cell/arch/x86_64/kernel/sys_x86_64.c
===================================================================
--- linux-cell.orig/arch/x86_64/kernel/sys_x86_64.c	2007-03-22 16:10:10.000000000 +1100
+++ linux-cell/arch/x86_64/kernel/sys_x86_64.c	2007-03-22 16:11:06.000000000 +1100
@@ -93,6 +93,9 @@ arch_get_unmapped_area(struct file *filp
 	unsigned long start_addr;
 	unsigned long begin, end;
 	
+	if (flags & MAP_FIXED)
+		return addr;
+
 	find_start_end(flags, &begin, &end); 
 
 	if (len > end)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 11/12] get_unmapped_area handles MAP_FIXED in generic code
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (9 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 10/12] get_unmapped_area handles MAP_FIXED in hugetlbfs Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 12/12] get_unmapped_area doesn't need hugetlbfs hacks anymore Benjamin Herrenschmidt
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

generic arch_get_unmapped_area() now handles MAP_FIXED. Now that
all implementations have been fixed, change the toplevel
get_unmapped_area() to call into arch or drivers for the MAP_FIXED
case.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 mm/mmap.c |   25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

Index: linux-cell/mm/mmap.c
===================================================================
--- linux-cell.orig/mm/mmap.c	2007-03-22 16:29:22.000000000 +1100
+++ linux-cell/mm/mmap.c	2007-03-22 16:30:06.000000000 +1100
@@ -1199,6 +1199,9 @@ arch_get_unmapped_area(struct file *filp
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED)
+		return addr;
+
 	if (addr) {
 		addr = PAGE_ALIGN(addr);
 		vma = find_vma(mm, addr);
@@ -1272,6 +1275,9 @@ arch_get_unmapped_area_topdown(struct fi
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED)
+		return addr;
+
 	/* requesting a specific address */
 	if (addr) {
 		addr = PAGE_ALIGN(addr);
@@ -1360,22 +1366,21 @@ get_unmapped_area(struct file *file, uns
 		unsigned long pgoff, unsigned long flags)
 {
 	unsigned long ret;
+	unsigned long (*get_area)(struct file *, unsigned long,
+				  unsigned long, unsigned long, unsigned long);
 
-	if (!(flags & MAP_FIXED)) {
-		unsigned long (*get_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
-
-		get_area = current->mm->get_unmapped_area;
-		if (file && file->f_op && file->f_op->get_unmapped_area)
-			get_area = file->f_op->get_unmapped_area;
-		addr = get_area(file, addr, len, pgoff, flags);
-		if (IS_ERR_VALUE(addr))
-			return addr;
-	}
+	get_area = current->mm->get_unmapped_area;
+	if (file && file->f_op && file->f_op->get_unmapped_area)
+		get_area = file->f_op->get_unmapped_area;
+	addr = get_area(file, addr, len, pgoff, flags);
+	if (IS_ERR_VALUE(addr))
+		return addr;
 
 	if (addr > TASK_SIZE - len)
 		return -ENOMEM;
 	if (addr & ~PAGE_MASK)
 		return -EINVAL;
+
 	if (file && is_file_hugepages(file))  {
 		/*
 		 * Check if the given range is hugepage aligned, and

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 10/12] get_unmapped_area handles MAP_FIXED in hugetlbfs
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (8 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 9/12] get_unmapped_area handles MAP_FIXED on x86_64 Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 11/12] get_unmapped_area handles MAP_FIXED in generic code Benjamin Herrenschmidt
  2007-04-24  5:33 ` [PATCH 12/12] get_unmapped_area doesn't need hugetlbfs hacks anymore Benjamin Herrenschmidt
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Generic hugetlb_get_unmapped_area() now handles MAP_FIXED by just
calling prepare_hugepage_range()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 fs/hugetlbfs/inode.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-cell/fs/hugetlbfs/inode.c
===================================================================
--- linux-cell.orig/fs/hugetlbfs/inode.c	2007-03-22 16:12:56.000000000 +1100
+++ linux-cell/fs/hugetlbfs/inode.c	2007-03-22 16:16:02.000000000 +1100
@@ -115,6 +115,12 @@ hugetlb_get_unmapped_area(struct file *f
 	if (len > TASK_SIZE)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (addr) {
 		addr = ALIGN(addr, HPAGE_SIZE);
 		vma = find_vma(mm, addr);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 12/12] get_unmapped_area doesn't need hugetlbfs hacks anymore
  2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
                   ` (10 preceding siblings ...)
  2007-04-24  5:33 ` [PATCH 11/12] get_unmapped_area handles MAP_FIXED in generic code Benjamin Herrenschmidt
@ 2007-04-24  5:33 ` Benjamin Herrenschmidt
  11 siblings, 0 replies; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-24  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Linux Memory Management

Remove the hugetlbfs specific hacks in toplevel get_unmapped_area() now
that all archs and hugetlbfs itself do the right thing for both cases.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: William Irwin <bill.irwin@oracle.com>

 mm/mmap.c |   16 ----------------
 1 file changed, 16 deletions(-)

Index: linux-cell/mm/mmap.c
===================================================================
--- linux-cell.orig/mm/mmap.c	2007-04-12 12:14:46.000000000 +1000
+++ linux-cell/mm/mmap.c	2007-04-12 12:14:47.000000000 +1000
@@ -1381,22 +1381,6 @@ get_unmapped_area(struct file *file, uns
 	if (addr & ~PAGE_MASK)
 		return -EINVAL;
 
-	if (file && is_file_hugepages(file))  {
-		/*
-		 * Check if the given range is hugepage aligned, and
-		 * can be made suitable for hugepages.
-		 */
-		ret = prepare_hugepage_range(addr, len, pgoff);
-	} else {
-		/*
-		 * Ensure that a normal request is not falling in a
-		 * reserved hugepage range.  For some archs like IA-64,
-		 * there is a separate region for hugepages.
-		 */
-		ret = is_hugepage_only_range(current->mm, addr, len);
-	}
-	if (ret)
-		return -EINVAL;
 	return addr;
 }
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm
  2007-04-24  5:33 ` [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm Benjamin Herrenschmidt
@ 2007-04-25  8:27   ` Russell King
  0 siblings, 0 replies; 16+ messages in thread
From: Russell King @ 2007-04-25  8:27 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Andrew Morton, linux-kernel, Linux Memory Management

On Tue, Apr 24, 2007 at 03:33:35PM +1000, Benjamin Herrenschmidt wrote:
> ARM already had a case for MAP_FIXED in arch_get_unmapped_area() though
> it was not called before. Fix the comment to reflect that it will now
> be called.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>

> 
>  arch/arm/mm/mmap.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> Index: linux-cell/arch/arm/mm/mmap.c
> ===================================================================
> --- linux-cell.orig/arch/arm/mm/mmap.c	2007-03-22 14:59:51.000000000 +1100
> +++ linux-cell/arch/arm/mm/mmap.c	2007-03-22 15:00:01.000000000 +1100
> @@ -49,8 +49,7 @@ arch_get_unmapped_area(struct file *filp
>  #endif
>  
>  	/*
> -	 * We should enforce the MAP_FIXED case.  However, currently
> -	 * the generic kernel code doesn't allow us to handle this.
> +	 * We enforce the MAP_FIXED case.
>  	 */
>  	if (flags & MAP_FIXED) {
>  		if (aliasing && flags & MAP_SHARED && addr & (SHMLBA - 1))
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64
  2007-04-12  2:20 ` [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64 Benjamin Herrenschmidt
@ 2007-04-12 22:30   ` William Lee Irwin III
  0 siblings, 0 replies; 16+ messages in thread
From: William Lee Irwin III @ 2007-04-12 22:30 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Andrew Morton, Linux Memory Management, linux-kernel

On Thu, Apr 12, 2007 at 12:20:31PM +1000, Benjamin Herrenschmidt wrote:
> Handle MAP_FIXED in hugetlb_get_unmapped_area on sparc64
> by just using prepare_hugepage_range()
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>  arch/sparc64/mm/hugetlbpage.c |    6 ++++++
>  1 file changed, 6 insertions(+)

Acked-by: William Irwin <bill.irwin@oracle.com>


-- wli

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64
  2007-04-12  2:20 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
@ 2007-04-12  2:20 ` Benjamin Herrenschmidt
  2007-04-12 22:30   ` William Lee Irwin III
  0 siblings, 1 reply; 16+ messages in thread
From: Benjamin Herrenschmidt @ 2007-04-12  2:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Memory Management, linux-kernel

Handle MAP_FIXED in hugetlb_get_unmapped_area on sparc64
by just using prepare_hugepage_range()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

 arch/sparc64/mm/hugetlbpage.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-cell/arch/sparc64/mm/hugetlbpage.c
===================================================================
--- linux-cell.orig/arch/sparc64/mm/hugetlbpage.c	2007-03-22 16:12:57.000000000 +1100
+++ linux-cell/arch/sparc64/mm/hugetlbpage.c	2007-03-22 16:15:33.000000000 +1100
@@ -175,6 +175,12 @@ hugetlb_get_unmapped_area(struct file *f
 	if (len > task_size)
 		return -ENOMEM;
 
+	if (flags & MAP_FIXED) {
+		if (prepare_hugepage_range(addr, len, pgoff))
+			return -EINVAL;
+		return addr;
+	}
+
 	if (addr) {
 		addr = ALIGN(addr, HPAGE_SIZE);
 		vma = find_vma(mm, addr);

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-04-25  8:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-24  5:33 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 1/12] get_unmapped_area handles MAP_FIXED on powerpc Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 2/12] get_unmapped_area handles MAP_FIXED on alpha Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 4/12] get_unmapped_area handles MAP_FIXED on frv Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 3/12] get_unmapped_area handles MAP_FIXED on arm Benjamin Herrenschmidt
2007-04-25  8:27   ` Russell King
2007-04-24  5:33 ` [PATCH 5/12] get_unmapped_area handles MAP_FIXED on i386 Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 6/12] get_unmapped_area handles MAP_FIXED on ia64 Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 7/12] get_unmapped_area handles MAP_FIXED on parisc Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64 Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 9/12] get_unmapped_area handles MAP_FIXED on x86_64 Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 10/12] get_unmapped_area handles MAP_FIXED in hugetlbfs Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 11/12] get_unmapped_area handles MAP_FIXED in generic code Benjamin Herrenschmidt
2007-04-24  5:33 ` [PATCH 12/12] get_unmapped_area doesn't need hugetlbfs hacks anymore Benjamin Herrenschmidt
  -- strict thread matches above, loose matches on Subject: below --
2007-04-12  2:20 [PATCH 0/12] Pass MAP_FIXED down to get_unmapped_area Benjamin Herrenschmidt
2007-04-12  2:20 ` [PATCH 8/12] get_unmapped_area handles MAP_FIXED on sparc64 Benjamin Herrenschmidt
2007-04-12 22:30   ` William Lee Irwin III

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).