Skip to contentSkip to conversation

mm/nommu.c: fix mmap failed due to the vm_region codes

PATCH In review [email protected] 2 participants 2 messages Sep 24, 2009

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

PATCH 1/1 mm/nommu.c: fix mmap failed due to the vm_region codes

From: Graff Yang <[email protected]>

Due to the new vm_region codes, mmap will failed if it is MAP_PRIVATE, or the get_unmapped_area() not do actual things.

---
 mm/nommu.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
mm/nommu.c +23 -7
index 8d48424..3a5e989 100644
@@ -1067,13 +1067,22 @@ static unsigned long determine_vm_flags(struct file *file,
  * set up a shared mapping on a file (the driver or filesystem provides and
  * pins the storage)
  */
-static int do_mmap_shared_file(struct vm_area_struct *vma)
+static int do_mmap_shared_file(struct vm_area_struct *vma,
+			   struct vm_region *region,
+			   unsigned long len)
 {
 	int ret;
 
 	ret = vma->vm_file->f_op->mmap(vma->vm_file, vma);
 	if (ret == 0) {
-		vma->vm_region->vm_top = vma->vm_region->vm_end;
+		vma->vm_region->vm_top = vma->vm_end;
+		if (region) {
+			if (!region->vm_start)
+				region->vm_start = vma->vm_start;
+			if (!region->vm_end)
+				region->vm_end = vma->vm_end;
+			add_nommu_region(region);
+		}
 		return ret;
 	}
 	if (ret != -ENOSYS)
@@ -1107,7 +1116,12 @@ static int do_mmap_private(struct vm_area_struct *vma,
 		if (ret == 0) {
 			/* shouldn't return success if we're not sharing */
 			BUG_ON(!(vma->vm_flags & VM_MAYSHARE));
-			vma->vm_region->vm_top = vma->vm_region->vm_end;
+			vma->vm_region->vm_top = vma->vm_end;
+			if (!region->vm_start)
+				region->vm_start = vma->vm_start;
+			if (!region->vm_end)
+				region->vm_end = vma->vm_end;
+			add_nommu_region(region);
 			return ret;
 		}
 		if (ret != -ENOSYS)
@@ -1187,6 +1201,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
 		memset(base, 0, rlen);
 	}
 
+	add_nommu_region(region);
 	return 0;
 
 error_free:
@@ -1325,7 +1340,7 @@ unsigned long do_mmap_pgoff(struct file *file,
 				vma->vm_flags |= VM_MAPPED_COPY;
 			} else {
 				kdebug("share mmap");
-				ret = do_mmap_shared_file(vma);
+				ret = do_mmap_shared_file(vma, NULL, 0);
 				if (ret < 0) {
 					vma->vm_region = NULL;
 					vma->vm_start = 0;
@@ -1370,11 +1385,10 @@ unsigned long do_mmap_pgoff(struct file *file,
 	}
 
 	vma->vm_region = region;
-	add_nommu_region(region);
 
 	/* set up the mapping */
 	if (file && vma->vm_flags & VM_SHARED)
-		ret = do_mmap_shared_file(vma);
+		ret = do_mmap_shared_file(vma, region, len);
 	else
 		ret = do_mmap_private(vma, region, len);
 	if (ret < 0)
@@ -1397,7 +1411,9 @@ share:
 	return result;
 
 error_put_region:
-	__put_nommu_region(region);
+	up_write(&nommu_region_sem);
+	fput(region->vm_file);
+	kmem_cache_free(vm_region_jar, region);
 	if (vma) {
 		if (vma->vm_file) {
 			fput(vma->vm_file);
Signature · 1 line
1.6.1
#1 lore raw
Quoted 2 lines · <[email protected]> wrote:

Due to the new vm_region codes, mmap will failed if it is MAP_PRIVATE, or the get_unmapped_area() not do actual things.

Hmmm... Seems one of my debugging patches had a work around for this - all it did was #ifdef-out the first if-statement in do_mmap_private(). That, however, prevents XIP.

Sadly, your patch doesn't completely fix the problem either. The BUG in add_nommu_region() barks.

Let me poke at it some more.

David