Skip to contentSkip to conversation

nommu: add page_align to mmap

PATCH In review Bob Liu 2 participants 11 messages May 6, 2011 – Jun 14, 2011

Subsystems (2)
lore
Share & tools
lore

Bob Liu

author
#0 lore raw

PATCH v2 1/1 nommu: add page_align to mmap

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align() which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Second munmap() may return -EINVAL[split file] error in cases when end is not page aligned(passed into from userspace) but vma->vm_end is aligned dure to split or driver's mmap() ops.

This patch add page align to fix those issues.

Changelog v1->v2:
- added more commit message

---
 mm/nommu.c |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)
mm/nommu.c +14 -10
index c4c542c..3febfd9 100644
@@ -1133,7 +1133,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
 			   unsigned long capabilities)
 {
 	struct page *pages;
-	unsigned long total, point, n, rlen;
+	unsigned long total, point, n;
 	void *base;
 	int ret, order;
 
@@ -1157,13 +1157,12 @@ static int do_mmap_private(struct vm_area_struct *vma,
 		 * make a private copy of the data and map that instead */
 	}
 
-	rlen = PAGE_ALIGN(len);
 
 	/* allocate some memory to hold the mapping
 	 * - note that this may not return a page-aligned address if the object
 	 *   we're allocating is smaller than a page
 	 */
-	order = get_order(rlen);
+	order = get_order(len);
 	kdebug("alloc order %d for %lx", order, len);
 
 	pages = alloc_pages(GFP_KERNEL, order);
@@ -1173,7 +1172,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
 	total = 1 << order;
 	atomic_long_add(total, &mmap_pages_allocated);
 
-	point = rlen >> PAGE_SHIFT;
+	point = len >> PAGE_SHIFT;
 
 	/* we allocated a power-of-2 sized page set, so we may want to trim off
 	 * the excess */
@@ -1195,7 +1194,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
 	base = page_address(pages);
 	region->vm_flags = vma->vm_flags |= VM_MAPPED_COPY;
 	region->vm_start = (unsigned long) base;
-	region->vm_end   = region->vm_start + rlen;
+	region->vm_end   = region->vm_start + len;
 	region->vm_top   = region->vm_start + (total << PAGE_SHIFT);
 
 	vma->vm_start = region->vm_start;
@@ -1211,15 +1210,15 @@ static int do_mmap_private(struct vm_area_struct *vma,
 
 		old_fs = get_fs();
 		set_fs(KERNEL_DS);
-		ret = vma->vm_file->f_op->read(vma->vm_file, base, rlen, &fpos);
+		ret = vma->vm_file->f_op->read(vma->vm_file, base, len, &fpos);
 		set_fs(old_fs);
 
 		if (ret < 0)
 			goto error_free;
 
 		/* clear the last little bit */
-		if (ret < rlen)
-			memset(base + ret, 0, rlen - ret);
+		if (ret < len)
+			memset(base + ret, 0, len - ret);
 
 	}
 
@@ -1268,6 +1267,7 @@ unsigned long do_mmap_pgoff(struct file *file,
 
 	/* we ignore the address hint */
 	addr = 0;
+	len = PAGE_ALIGN(len);
 
 	/* we've determined that we can make the mapping, now translate what we
 	 * now know into VMA flags */
@@ -1645,14 +1645,16 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
 {
 	struct vm_area_struct *vma;
 	struct rb_node *rb;
-	unsigned long end = start + len;
+	unsigned long end;
 	int ret;
 
 	kenter(",%lx,%zx", start, len);
 
-	if (len == 0)
+	if ((len = PAGE_ALIGN(len)) == 0)
 		return -EINVAL;
 
+	end = start + len;
+
 	/* find the first potentially overlapping VMA */
 	vma = find_vma(mm, start);
 	if (!vma) {
@@ -1773,6 +1775,8 @@ unsigned long do_mremap(unsigned long addr,
 	struct vm_area_struct *vma;
 
 	/* insanity checks first */
+	old_len = PAGE_ALIGN(old_len);
+	new_len = PAGE_ALIGN(new_len);
 	if (old_len == 0 || new_len == 0)
 		return (unsigned long) -EINVAL;
 
Signature · 9 lines
1.6.3.3


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

Hi Bob,

Quoted 11 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align() which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Second munmap() may return -EINVAL[split file] error in cases when end is not page aligned(passed into from userspace) but vma->vm_end is aligned dure to split or driver's mmap() ops.

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

Quoted 109 lines

Changelog v1->v2:
- added more commit message

---
  mm/nommu.c |   24 ++++++++++++++----------
  1 files changed, 14 insertions(+), 10 deletions(-)
mm/nommu.c +14 -10
index c4c542c..3febfd9 100644
@@ -1133,7 +1133,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
  			   unsigned long capabilities)
  {
  	struct page *pages;
-	unsigned long total, point, n, rlen;
+	unsigned long total, point, n;
  	void *base;
  	int ret, order;
 
@@ -1157,13 +1157,12 @@ static int do_mmap_private(struct vm_area_struct *vma,
  		 * make a private copy of the data and map that instead */
  	}
 
-	rlen = PAGE_ALIGN(len);
 
  	/* allocate some memory to hold the mapping
  	 * - note that this may not return a page-aligned address if the object
  	 *   we're allocating is smaller than a page
  	 */
-	order = get_order(rlen);
+	order = get_order(len);
  	kdebug("alloc order %d for %lx", order, len);
 
  	pages = alloc_pages(GFP_KERNEL, order);
@@ -1173,7 +1172,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
  	total = 1<<  order;
  	atomic_long_add(total,&mmap_pages_allocated);
 
-	point = rlen>>  PAGE_SHIFT;
+	point = len>>  PAGE_SHIFT;
 
  	/* we allocated a power-of-2 sized page set, so we may want to trim off
  	 * the excess */
@@ -1195,7 +1194,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
  	base = page_address(pages);
  	region->vm_flags = vma->vm_flags |= VM_MAPPED_COPY;
  	region->vm_start = (unsigned long) base;
-	region->vm_end   = region->vm_start + rlen;
+	region->vm_end   = region->vm_start + len;
  	region->vm_top   = region->vm_start + (total<<  PAGE_SHIFT);
 
  	vma->vm_start = region->vm_start;
@@ -1211,15 +1210,15 @@ static int do_mmap_private(struct vm_area_struct *vma,
 
  		old_fs = get_fs();
  		set_fs(KERNEL_DS);
-		ret = vma->vm_file->f_op->read(vma->vm_file, base, rlen,&fpos);
+		ret = vma->vm_file->f_op->read(vma->vm_file, base, len,&fpos);
  		set_fs(old_fs);
 
  		if (ret<  0)
  			goto error_free;
 
  		/* clear the last little bit */
-		if (ret<  rlen)
-			memset(base + ret, 0, rlen - ret);
+		if (ret<  len)
+			memset(base + ret, 0, len - ret);
 
  	}
 
@@ -1268,6 +1267,7 @@ unsigned long do_mmap_pgoff(struct file *file,
 
  	/* we ignore the address hint */
  	addr = 0;
+	len = PAGE_ALIGN(len);
 
  	/* we've determined that we can make the mapping, now translate what we
  	 * now know into VMA flags */
@@ -1645,14 +1645,16 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
  {
  	struct vm_area_struct *vma;
  	struct rb_node *rb;
-	unsigned long end = start + len;
+	unsigned long end;
  	int ret;
 
  	kenter(",%lx,%zx", start, len);
 
-	if (len == 0)
+	if ((len = PAGE_ALIGN(len)) == 0)
  		return -EINVAL;
 
+	end = start + len;
+
  	/* find the first potentially overlapping VMA */
  	vma = find_vma(mm, start);
  	if (!vma) {
@@ -1773,6 +1775,8 @@ unsigned long do_mremap(unsigned long addr,
  	struct vm_area_struct *vma;
 
  	/* insanity checks first */
+	old_len = PAGE_ALIGN(old_len);
+	new_len = PAGE_ALIGN(new_len);
  	if (old_len == 0 || new_len == 0)
  		return (unsigned long) -EINVAL;
 
Signature · 12 lines
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#2 lore raw
Quoted 24 lines · Greg Ungerer

Hi Bob,

Quoted 10 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is
page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Quoted 7 lines

Second munmap() may return -EINVAL[split file] error in cases when end is not
page aligned(passed into from userspace) but vma->vm_end is aligned dure to
split or driver's mmap() ops.

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

 ...
 VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Thanks!

Quoted 139 lines

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

Quoted 112 lines

Changelog v1->v2:
- added more commit message

---
 mm/nommu.c |   24 ++++++++++++++----------

 1 files changed, 14 insertions(+), 10 deletions(-)
mm/nommu.c +1 -2
index c4c542c..3febfd9 100644
@@ -1133,7 +1133,7 @@ static int do_mmap_private(struct vm_area_struct
 *vma,
                           unsigned long capabilities)
  {
        struct page *pages;
-       unsigned long total, point, n, rlen;
+       unsigned long total, point, n;
        void *base;
        int ret, order;
@@ -1157,13 +1157,12 @@ static int do_mmap_private(struct vm_area_struct
 *vma,
                 * make a private copy of the data and map that instead */
        }
 
-       rlen = PAGE_ALIGN(len);
 
        /* allocate some memory to hold the mapping
         * - note that this may not return a page-aligned address if the

object
        *   we're allocating is smaller than a page */
-       order = get_order(rlen);
+       order = get_order(len); kdebug("alloc order %d for %lx", order, len);

       pages = alloc_pages(GFP_KERNEL, order);

mm/nommu.c +1 -1
@@ -1173,7 +1172,7 @@ static int do_mmap_private(struct vm_area_struct
 *vma,
        total = 1<<  order;
        atomic_long_add(total,&mmap_pages_allocated);
 
-       point = rlen>>  PAGE_SHIFT;
+       point = len>>  PAGE_SHIFT;
 
        /* we allocated a power-of-2 sized page set, so we may want to trim

off
        * the excess */

mm/nommu.c +1 -1
@@ -1195,7 +1194,7 @@ static int do_mmap_private(struct vm_area_struct
 *vma,
        base = page_address(pages);
        region->vm_flags = vma->vm_flags |= VM_MAPPED_COPY;
        region->vm_start = (unsigned long) base;
-       region->vm_end   = region->vm_start + rlen;
+       region->vm_end   = region->vm_start + len;
        region->vm_top   = region->vm_start + (total<<  PAGE_SHIFT);
 

       vma->vm_start = region->vm_start;

mm/nommu.c +3 -3
@@ -1211,15 +1210,15 @@ static int do_mmap_private(struct vm_area_struct
 *vma,
 
                old_fs = get_fs();
                set_fs(KERNEL_DS);
-               ret = vma->vm_file->f_op->read(vma->vm_file, base,
 rlen,&fpos);
+               ret = vma->vm_file->f_op->read(vma->vm_file, base,
 len,&fpos);
                set_fs(old_fs);
 
                if (ret<  0)
                        goto error_free;
 
                /* clear the last little bit */
-               if (ret<  rlen)
-                       memset(base + ret, 0, rlen - ret);
+               if (ret<  len)
+                       memset(base + ret, 0, len - ret);

       }

mm/nommu.c +1 -0
@@ -1268,6 +1267,7 @@ unsigned long do_mmap_pgoff(struct file *file,
 
        /* we ignore the address hint */
        addr = 0;
+       len = PAGE_ALIGN(len);
 
        /* we've determined that we can make the mapping, now translate

what we
        * now know into VMA flags */

mm/nommu.c +4 -2
@@ -1645,14 +1645,16 @@ int do_munmap(struct mm_struct *mm, unsigned long
 start, size_t len)
  {
        struct vm_area_struct *vma;
        struct rb_node *rb;
-       unsigned long end = start + len;
+       unsigned long end;
        int ret;
 
        kenter(",%lx,%zx", start, len);
 
-       if (len == 0)
+       if ((len = PAGE_ALIGN(len)) == 0)
                return -EINVAL;
 
+       end = start + len;
+
        /* find the first potentially overlapping VMA */
        vma = find_vma(mm, start);

       if (!vma) {

mm/nommu.c unsigned long do_mremap(unsigned long addr, · line 1782

Quoted 8 lines
mm/nommu.c +2 -0
@@ -1773,6 +1775,8 @@ unsigned long do_mremap(unsigned long addr,
        struct vm_area_struct *vma;
 
        /* insanity checks first */
+       old_len = PAGE_ALIGN(old_len);
+       new_len = PAGE_ALIGN(new_len);
        if (old_len == 0 || new_len == 0)
                return (unsigned long) -EINVAL;
 

--
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected] SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888 8 Gardner Close                             FAX:         +61 7 3217 5323 Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

Signature · 9 lines
Regards,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Hi Bob,

Quoted 34 lines · Bob Liu
Quoted 24 lines · Greg Ungerer

Hi Bob,

Quoted 10 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is
page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Quoted 7 lines

Second munmap() may return -EINVAL[split file] error in cases when end is not
page aligned(passed into from userspace) but vma->vm_end is aligned dure to
split or driver's mmap() ops.

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) áUnable to mmap process text, errno 22

Quoted 3 lines

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Yep, with debug on:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==> do_mmap_pgoff(,0,6780,5,1002,0)
<== do_mmap_pgoff() = -22
Unable to mmap process text, errno 22

I can confirm that the PAGE_ALIGN(len) change in do_mmap_pgoff() is enough to cause this too.

Regards
Greg

Quoted 8 lines
Quoted 8 lines

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

------------------------------------------------------------------------

Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#4 lore raw

Hi, Greg

Quoted 44 lines · Greg Ungerer

Hi Bob,

Quoted 37 lines · Bob Liu
Quoted 26 lines · Greg Ungerer

Hi Bob,

Quoted 10 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is
page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Quoted 8 lines

Second munmap() may return -EINVAL[split file] error in cases when end is
not
page aligned(passed into from userspace) but vma->vm_end is aligned dure to
split or driver's mmap() ops.

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) áUnable to mmap process text, errno 22

Quoted 3 lines

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Quoted 9 lines

Yep, with debug on:

 ...
 VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==> do_mmap_pgoff(,0,6780,5,1002,0)
 <== do_mmap_pgoff() = -22
 Unable to mmap process text, errno 22

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

Thanks!

Quoted 24 lines

I can confirm that the PAGE_ALIGN(len) change in do_mmap_pgoff() is enough to cause this too.

Regards
Greg

Quoted 8 lines
Quoted 8 lines

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected] SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888 8 Gardner Close                             FAX:         +61 7 3217 5323 Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

Signature · 9 lines
Regards,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

Hi Bob,

Quoted 57 lines · Bob Liu

Hi, Greg

Quoted 44 lines · Greg Ungerer

Hi Bob,

Quoted 37 lines · Bob Liu
Quoted 26 lines · On Fri, Jun 3, 2011 at 2:37 PM, Greg Ungerer<[email protected]> áwrote:

Hi Bob,

Quoted 10 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start is
page aligned which is true on mmu arch but not on nommu. eg: uvc camera driver.

Quoted 8 lines

Second munmap() may return -EINVAL[split file] error in cases when end is
not
page aligned(passed into from userspace) but vma->vm_end is aligned dure to
split or driver's mmap() ops.

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) áUnable to mmap process text, errno 22

Quoted 3 lines

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Quoted 9 lines

Yep, with debug on:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) á==> do_mmap_pgoff(,0,6780,5,1002,0)
á<== do_mmap_pgoff() = -22
áUnable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

          addr = file->f_op->get_unmapped_area(file, addr, len,
                                                      pgoff, flags);

Theres only one call of this inside do_mmap_pgoff() so you its easy to find.

Regards
Greg

Quoted 18 lines
Quoted 18 lines

I can confirm that the PAGE_ALIGN(len) change in do_mmap_pgoff() is enough to cause this too.

Regards
Greg

Quoted 8 lines
Quoted 8 lines

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

Quoted 7 lines
Quoted 6 lines

------------------------------------------------------------------------
Greg Ungerer á-- áPrincipal Engineer á á á áEMAIL: á á [email protected] SnapGear Group, McAfee á á á á á á á á á á áPHONE: á á á +61 7 3435 2888 8 Gardner Close á á á á á á á á á á á á á á FAX: á á á á +61 7 3217 5323 Milton, QLD, 4064, Australia á á á á á á á áWEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#6 lore raw
Quoted 76 lines · Greg Ungerer

Hi Bob,

Quoted 63 lines · Bob Liu

Hi, Greg

Quoted 49 lines · Greg Ungerer

Hi Bob,

Quoted 41 lines · Bob Liu
Quoted 29 lines · On Fri, Jun 3, 2011 at 2:37 PM, Greg Ungerer<[email protected]> áwrote:

Hi Bob,

Quoted 20 lines · Bob Liu

Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which isn't consist with mmu arch and cause some issues.

First, some drivers' mmap() function depends on vma->vm_end - vma->start
is
page aligned which is true on mmu arch but not on nommu. eg: uvc camera
driver.

Second munmap() may return -EINVAL[split file] error in cases when end is
not
page aligned(passed into from userspace) but vma->vm_end is aligned dure
to
split or driver's mmap() ops.

Quoted 1 line

This patch add page align to fix those issues.

This is actually causing me problems on head at the moment. git bisected to this patch as the cause.

Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) áUnable to mmap process text, errno 22

Quoted 3 lines

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Quoted 9 lines

Yep, with debug on:

á...
áVFS: Mounted root (romfs filesystem) readonly on device 31:0. áFreeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) á==>  do_mmap_pgoff(,0,6780,5,1002,0)
á<== do_mmap_pgoff() = -22
áUnable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

Quoted 6 lines

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

         addr = file->f_op->get_unmapped_area(file, addr, len, pgoff, flags);

Thanks for this information.
But it's a callback function. I still can't know what's the problem maybe. Would you do me a favor to do more trace to see where it callback to, fs or some driver etc..?

Quoted 26 lines

Theres only one call of this inside do_mmap_pgoff() so you its easy to find.

Regards
Greg

Quoted 17 lines
Quoted 17 lines

I can confirm that the PAGE_ALIGN(len) change in do_mmap_pgoff() is enough to cause this too.

Regards
Greg

Quoted 8 lines
Quoted 8 lines

I haven't really debugged it any further yet. But that error message comes from fs/binfmt_flat.c, it is reporting a failed do_mmap() call.

Reverting that this patch and no more problem.

Regards
Greg

Signature · 9 lines
Regards,
--Bob

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Hi Bob,

Quoted 36 lines · Bob Liu
Quoted 35 lines · Greg Ungerer
Quoted 23 lines
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

Quoted 3 lines

Oh, bad news. I will try to reproduce it on my board.
If you are free please enable debug in nommu.c and then we can see what caused the problem.

Quoted 9 lines

Yep, with debug on:

­...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==> ádo_mmap_pgoff(,0,6780,5,1002,0)
<== do_mmap_pgoff() = -22
Unable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

Quoted 8 lines
Quoted 3 lines

addr = file->f_op->get_unmapped_area(file, addr, len,

                                           ¡pgoff, flags);

Thanks for this information.
But it's a callback function. I still can't know what's the problem maybe. Would you do me a favor to do more trace to see where it callback to, fs or some driver etc..?

Its calling to romfs_get_unmapped_area() [fs/romfs/mmap-nommu.c]. It is being called with:

romfs_get_unmapped_area(addr=0,len=7000,pgoff=0,flags=1002)

This is failing the first size check because isize comes back as 0x6ca8, and this is smaller then len (0x7000). Thus returning -EINVAL.

That code is trying to map the contents of the file /bin/init directly from the romfs filesystem (which is in RAM). The init binary is 0x6ca8 bytes in size (that is the isize above).

Regards
Greg

------------------------------------------------------------------------

Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#8 lore raw

Hi, Greg

Quoted 51 lines · Greg Ungerer

Hi Bob,

Quoted 39 lines · Bob Liu
Quoted 37 lines · Greg Ungerer
Quoted 25 lines
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

Quoted 4 lines

Oh, bad news. I will try to reproduce it on my board. If you are free please enable debug in nommu.c and then we can see what
caused the problem.

Quoted 9 lines

Yep, with debug on:

­...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==>  Ã¡do_mmap_pgoff(,0,6780,5,1002,0)
<== do_mmap_pgoff() = -22
Unable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

Quoted 8 lines
Quoted 3 lines

addr = file->f_op->get_unmapped_area(file, addr, len, ¡pgoff, flags);

Thanks for this information.
But it's a callback function. I still can't know what's the problem maybe. Would you do me a favor to do more trace to see where it callback to, fs or some driver etc..?

Quoted 9 lines

Its calling to romfs_get_unmapped_area() [fs/romfs/mmap-nommu.c]. It is being called with:

 romfs_get_unmapped_area(addr=0,len=7000,pgoff=0,flags=1002)

This is failing the first size check because isize comes back as 0x6ca8, and this is smaller then len (0x7000). Thus returning -EINVAL.

I look into file fs/romfs/mmap-nommu.c based on your trace. In my opinion, romfs_get_unmapped_area() in mmap-nommu.c is buggy. Would you please try below commit.
Thanks a lot.

#9 lore raw

Hi Bob,

Quoted 59 lines · Bob Liu

Hi, Greg

Quoted 56 lines · Greg Ungerer

Hi Bob,

Quoted 39 lines · Bob Liu
Quoted 37 lines · On Wed, Jun 8, 2011 at 6:19 PM, Greg Ungerer<[email protected]> A!wrote:
Quoted 25 lines
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

Quoted 4 lines

Oh, bad news. I will try to reproduce it on my board. If you are free please enable debug in nommu.c and then we can see what
caused the problem.

Quoted 9 lines

Yep, with debug on:

A!...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==> A!a??A-do_mmap_pgoff(,0,6780,5,1002,0)
<== do_mmap_pgoff() = -22
Unable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

Quoted 8 lines
Quoted 3 lines

addr = file->f_op->get_unmapped_area(file, addr, len,

                                              pgoff, flags);

Thanks for this information.
But it's a callback function. I still can't know what's the problem maybe. Would you do me a favor to do more trace to see where it callback to, fs or some driver etc..?

Its calling to romfs_get_unmapped_area() [fs/romfs/mmap-nommu.c]. It is being called with:

A!romfs_get_unmapped_area(addr=0,len=7000,pgoff=0,flags=1002)

Quoted 8 lines
Quoted 4 lines

This is failing the first size check because isize comes back as 0x6ca8, and this is smaller then len (0x7000). Thus returning -EINVAL.

I look into file fs/romfs/mmap-nommu.c based on your trace. In my opinion, romfs_get_unmapped_area() in mmap-nommu.c is buggy. Would you please try below commit.

Sure thing. I am away for the next couple of days, so I am not going to be able to try it until Tuesday. I'll let you know how it goes then.

Regards
Greg

Quoted 52 lines

Thanks a lot.

from 786add5286ffb476807cb198d7b2c5455e9fb533 Mon Sep 17 00:00:00 2001
From: Bob Liu<[email protected]>
Date: Fri, 10 Jun 2011 13:34:48 +0800
Subject: [PATCH] romfs: fix romfs_get_unmapped_area() param check

romfs_get_unmapped_area() check len param without considering PAGE_ALIGN which will cause do_mmap_pgoff() return -EINVAL error after commit f67d9b1576c.

This patch fix the param check by changing it to the same way as function ramfs_nommu_get_unmapped_area() did in ramfs/file-nommu.c.

---
  fs/romfs/mmap-nommu.c |    8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)
fs/romfs/mmap-nommu.c +6 -2
index f0511e8..eed9942 100644
@@ -27,14 +27,18 @@ static unsigned long
 romfs_get_unmapped_area(struct file *file,
  {
         struct inode *inode = file->f_mapping->host;
         struct mtd_info *mtd = inode->i_sb->s_mtd;
-       unsigned long isize, offset;
+       unsigned long isize, offset, maxpages, lpages;
 
         if (!mtd)
                 goto cant_map_directly;
 
+       /* the mapping mustn't extend beyond the EOF */
+       lpages = (len + PAGE_SIZE - 1)>>  PAGE_SHIFT;
         isize = i_size_read(inode);
         offset = pgoff<<  PAGE_SHIFT;
-       if (offset>  isize || len>  isize || offset>  isize - len)
+
+       maxpages = (isize + PAGE_SIZE - 1)>>  PAGE_SHIFT;
+       if ((pgoff>= maxpages) || (maxpages - pgoff<  lpages))
                 return (unsigned long) -EINVAL;
 
         /* we need to call down to the MTD layer to do the actual mapping */

--
1.6.3.3

Quoted 4 lines

That code is trying to map the contents of the file /bin/init directly from the romfs filesystem (which is in RAM). The init binary is 0x6ca8 bytes in size (that is the isize above).

Signature · 12 lines
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close,                            FAX:         +61 7 3891 3630
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw
In reply to Bob Liu

Hi Bob,

Quoted 59 lines · Bob Liu

Hi, Greg

Quoted 56 lines · Greg Ungerer

Hi Bob,

Quoted 39 lines · Bob Liu
Quoted 37 lines · On Wed, Jun 8, 2011 at 6:19 PM, Greg Ungerer<[email protected]> áwrote:
Quoted 25 lines
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines

When booting on a ColdFire (m68knommu) target the init process (or there abouts at least) fails. Last console messages are:

...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x401aa000 - 0x401b6000) Unable to mmap process text, errno 22

Quoted 4 lines

Oh, bad news. I will try to reproduce it on my board. If you are free please enable debug in nommu.c and then we can see what
caused the problem.

Quoted 9 lines

Yep, with debug on:

¡...
VFS: Mounted root (romfs filesystem) readonly on device 31:0. Freeing unused kernel memory: 52k freed (0x4018c000 - 0x40198000) ==> á├ído_mmap_pgoff(,0,6780,5,1002,0)
<== do_mmap_pgoff() = -22
Unable to mmap process text, errno 22

Quoted 4 lines

Since I can't reproduce this problem, could you please attach the whole dmesg log with nommu debug on or
you can step into to see why errno 22 is returned, is it returned by do_mmap_private()?

There was no other debug messages with debug turned on in nommu.c. (I can give you the boot msgs before this if you want, but there was no nommu.c debug in it).

But I did trace it into do_mmap_pgoff() to see what was failing. It fails based on the return value from:

Quoted 8 lines
Quoted 3 lines

addr = file->f_op->get_unmapped_area(file, addr, len,
á á á á á á á á á á á á á á á á á á á á á ípgoff, flags);

Thanks for this information.
But it's a callback function. I still can't know what's the problem maybe. Would you do me a favor to do more trace to see where it callback to, fs or some driver etc..?

Its calling to romfs_get_unmapped_area() [fs/romfs/mmap-nommu.c]. It is being called with:

áromfs_get_unmapped_area(addr=0,len=7000,pgoff=0,flags=1002)

Quoted 8 lines
Quoted 4 lines

This is failing the first size check because isize comes back as 0x6ca8, and this is smaller then len (0x7000). Thus returning -EINVAL.

I look into file fs/romfs/mmap-nommu.c based on your trace. In my opinion, romfs_get_unmapped_area() in mmap-nommu.c is buggy. Would you please try below commit.

Yep, this fixes it. I think David (Howells) originally made those changes, not sure if he wants to add anything here.

Thanks
Greg

Quoted 52 lines

Thanks a lot.

from 786add5286ffb476807cb198d7b2c5455e9fb533 Mon Sep 17 00:00:00 2001
From: Bob Liu<[email protected]>
Date: Fri, 10 Jun 2011 13:34:48 +0800
Subject: [PATCH] romfs: fix romfs_get_unmapped_area() param check

romfs_get_unmapped_area() check len param without considering PAGE_ALIGN which will cause do_mmap_pgoff() return -EINVAL error after commit f67d9b1576c.

This patch fix the param check by changing it to the same way as function ramfs_nommu_get_unmapped_area() did in ramfs/file-nommu.c.

---
  fs/romfs/mmap-nommu.c |    8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)
fs/romfs/mmap-nommu.c +6 -2
index f0511e8..eed9942 100644
@@ -27,14 +27,18 @@ static unsigned long
 romfs_get_unmapped_area(struct file *file,
  {
         struct inode *inode = file->f_mapping->host;
         struct mtd_info *mtd = inode->i_sb->s_mtd;
-       unsigned long isize, offset;
+       unsigned long isize, offset, maxpages, lpages;
 
         if (!mtd)
                 goto cant_map_directly;
 
+       /* the mapping mustn't extend beyond the EOF */
+       lpages = (len + PAGE_SIZE - 1)>>  PAGE_SHIFT;
         isize = i_size_read(inode);
         offset = pgoff<<  PAGE_SHIFT;
-       if (offset>  isize || len>  isize || offset>  isize - len)
+
+       maxpages = (isize + PAGE_SIZE - 1)>>  PAGE_SHIFT;
+       if ((pgoff>= maxpages) || (maxpages - pgoff<  lpages))
                 return (unsigned long) -EINVAL;
 
         /* we need to call down to the MTD layer to do the actual mapping */

--
1.6.3.3

Quoted 4 lines

That code is trying to map the contents of the file /bin/init directly from the romfs filesystem (which is in RAM). The init binary is 0x6ca8 bytes in size (that is the isize above).

Signature · 12 lines
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     [email protected]
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>