All of lore.kernel.org
 help / color / mirror / Atom feed
From: <graff.yang@gmail.com>
To: <dhowells@redhat.com>, <linux-kernel@vger.kernel.org>
Cc: <akpm@linux-foundation.org>,
	<uclinux-dist-devel@blackfin.uclinux.org>, <graf.yang@analog.com>,
	Graff Yang <graff.yang@gmail.com>
Subject: [PATCH] mm/nommu.c: fix mmap failed due to the vm_region codes
Date: Thu, 24 Sep 2009 19:37:59 +0800	[thread overview]
Message-ID: <1253792279-30623-1-git-send-email-graff.yang@gmail.com> (raw)

From: Graff Yang <graff.yang@gmail.com>

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

Signed-off-by: Graff Yang <graff.yang@gmail.com>
---
 mm/nommu.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/mm/nommu.c b/mm/nommu.c
index 8d48424..3a5e989 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -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);
-- 
1.6.1


             reply	other threads:[~2009-09-24 11:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-24 11:37 graff.yang [this message]
2009-09-24 12:29 ` [PATCH] mm/nommu.c: fix mmap failed due to the vm_region codes David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253792279-30623-1-git-send-email-graff.yang@gmail.com \
    --to=graff.yang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=graf.yang@analog.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=uclinux-dist-devel@blackfin.uclinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.