* [PATCH] nommu: add page_align to mmap
@ 2011-04-27 7:12 Bob Liu
2011-05-04 21:13 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Bob Liu @ 2011-04-27 7:12 UTC (permalink / raw)
To: linux-mm; +Cc: akpm, dhowells, lethal, gerg, walken, daniel-gl, vapier, Bob Liu
Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
which is incorrect and not consist with mmu arch.
This patch fix it.
Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
mm/nommu.c | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/mm/nommu.c b/mm/nommu.c
index c4c542c..3febfd9 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -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;
--
1.6.3.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] nommu: add page_align to mmap
2011-04-27 7:12 [PATCH] nommu: add page_align to mmap Bob Liu
@ 2011-05-04 21:13 ` Andrew Morton
2011-05-05 1:38 ` Greg Ungerer
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2011-05-04 21:13 UTC (permalink / raw)
To: Bob Liu
Cc: linux-mm, dhowells, lethal, gerg, walken, daniel-gl, vapier,
Geert Uytterhoeven
On Wed, 27 Apr 2011 15:12:14 +0800
Bob Liu <lliubbo@gmail.com> wrote:
> Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
> which is incorrect and not consist with mmu arch.
> This patch fix it.
>
Can you explain this fully please? What was the user-observeable
behaviour before the patch, and after?
And some input from nommu maintainers would be nice.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nommu: add page_align to mmap
2011-05-04 21:13 ` Andrew Morton
@ 2011-05-05 1:38 ` Greg Ungerer
2011-05-05 10:19 ` Bob Liu
0 siblings, 1 reply; 5+ messages in thread
From: Greg Ungerer @ 2011-05-05 1:38 UTC (permalink / raw)
To: Bob Liu
Cc: Andrew Morton, linux-mm, dhowells, lethal, gerg, walken,
daniel-gl, vapier, Geert Uytterhoeven
On 05/05/11 07:13, Andrew Morton wrote:
> On Wed, 27 Apr 2011 15:12:14 +0800
> Bob Liu<lliubbo@gmail.com> wrote:
>
>> Currently on nommu arch mmap(),mremap() and munmap() doesn't do page_align()
>> which is incorrect and not consist with mmu arch.
>> This patch fix it.
>>
>
> Can you explain this fully please? What was the user-observeable
> behaviour before the patch, and after?
>
> And some input from nommu maintainers would be nice.
Its not obvious to me that there is a problem here. Are there
any issues caused by the current behavior that this fixes?
Regards
Greg
------------------------------------------------------------------------
Greg Ungerer -- Principal Engineer EMAIL: gerg@snapgear.com
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 majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nommu: add page_align to mmap
2011-05-05 1:38 ` Greg Ungerer
@ 2011-05-05 10:19 ` Bob Liu
2011-05-06 0:32 ` Greg Ungerer
0 siblings, 1 reply; 5+ messages in thread
From: Bob Liu @ 2011-05-05 10:19 UTC (permalink / raw)
To: Greg Ungerer
Cc: Andrew Morton, linux-mm, dhowells, lethal, gerg, walken,
daniel-gl, vapier, Geert Uytterhoeven
On Thu, May 5, 2011 at 9:38 AM, Greg Ungerer <gerg@snapgear.com> wrote:
> On 05/05/11 07:13, Andrew Morton wrote:
>>
>> On Wed, 27 Apr 2011 15:12:14 +0800
>> Bob Liu<lliubbo@gmail.com> wrote:
>>
>>> Currently on nommu arch mmap(),mremap() and munmap() doesn't do
>>> page_align()
>>> which is incorrect and not consist with mmu arch.
>>> This patch fix it.
>>>
>>
>> Can you explain this fully please? What was the user-observeable
>> behaviour before the patch, and after?
>>
>> And some input from nommu maintainers would be nice.
>
> Its not obvious to me that there is a problem here. Are there
> any issues caused by the current behavior that this fixes?
>
Yes, there is a issue.
Some drivers' mmap() function depend on (vma->vm_end - vma->start) is
page aligned which is true on mmu arch but not on nommu.
eg: uvc camera driver.
What's more, sometimes I got munmap() error.
The reason is split file: mm/nommu.c
do {
1614 if (start > vma->vm_start) {
1615 kleave(" = -EINVAL [miss]");
1616 return -EINVAL;
1617 }
1618 if (end == vma->vm_end)
1619 goto erase_whole_vma;
<<=====================here
1620 rb = rb_next(&vma->vm_rb);
1621 vma = rb_entry(rb, struct vm_area_struct, vm_rb);
1622 } while (rb);
1623 kleave(" = -EINVAL [split file]");
Because end is not page aligned (passed into from userspace) while
some unknown reason
vma->vm_end is aligned, this loop will fail and -EINVAL[split file]
error returned.
But it's hard to reproduce.
And in my opinion consist with mmu alway a better choice.
Thanks for your review.
--
Regards,
--Bob
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] nommu: add page_align to mmap
2011-05-05 10:19 ` Bob Liu
@ 2011-05-06 0:32 ` Greg Ungerer
0 siblings, 0 replies; 5+ messages in thread
From: Greg Ungerer @ 2011-05-06 0:32 UTC (permalink / raw)
To: Bob Liu
Cc: Andrew Morton, linux-mm, dhowells, lethal, gerg, walken,
daniel-gl, vapier, Geert Uytterhoeven
Hi Bob,
On 05/05/11 20:19, Bob Liu wrote:
> On Thu, May 5, 2011 at 9:38 AM, Greg Ungerer<gerg@snapgear.com> wrote:
>> On 05/05/11 07:13, Andrew Morton wrote:
>>>
>>> On Wed, 27 Apr 2011 15:12:14 +0800
>>> Bob Liu<lliubbo@gmail.com> áwrote:
>>>
>>>> Currently on nommu arch mmap(),mremap() and munmap() doesn't do
>>>> page_align()
>>>> which is incorrect and not consist with mmu arch.
>>>> This patch fix it.
>>>>
>>>
>>> Can you explain this fully please? áWhat was the user-observeable
>>> behaviour before the patch, and after?
>>>
>>> And some input from nommu maintainers would be nice.
>>
>> Its not obvious to me that there is a problem here. Are there
>> any issues caused by the current behavior that this fixes?
>>
>
> Yes, there is a issue.
>
> Some drivers' mmap() function depend on (vma->vm_end - vma->start) is
> page aligned which is true on mmu arch but not on nommu.
> eg: uvc camera driver.
>
> What's more, sometimes I got munmap() error.
> The reason is split file: mm/nommu.c
> do {
> 1614 if (start> vma->vm_start) {
> 1615 kleave(" = -EINVAL [miss]");
> 1616 return -EINVAL;
> 1617 }
> 1618 if (end == vma->vm_end)
> 1619 goto erase_whole_vma;
>
> <<=====================here
> 1620 rb = rb_next(&vma->vm_rb);
> 1621 vma = rb_entry(rb, struct vm_area_struct, vm_rb);
> 1622 } while (rb);
> 1623 kleave(" = -EINVAL [split file]");
>
> Because end is not page aligned (passed into from userspace) while
> some unknown reason
> vma->vm_end is aligned, this loop will fail and -EINVAL[split file]
> error returned.
> But it's hard to reproduce.
>
> And in my opinion consist with mmu alway a better choice.
>
> Thanks for your review.
Ok, makes sense. Can you add some of this writeup to the patch
commit message?
Regards
Greg
------------------------------------------------------------------------
Greg Ungerer -- Principal Engineer EMAIL: gerg@snapgear.com
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 majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-05-06 0:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-27 7:12 [PATCH] nommu: add page_align to mmap Bob Liu
2011-05-04 21:13 ` Andrew Morton
2011-05-05 1:38 ` Greg Ungerer
2011-05-05 10:19 ` Bob Liu
2011-05-06 0:32 ` Greg Ungerer
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).