linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] NOMMU: Lock i_mmap_mutex for access to the VMA prio list
@ 2012-02-23 13:50 David Howells
  2012-02-23 13:50 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Howells @ 2012-02-23 13:50 UTC (permalink / raw)
  To: torvalds
  Cc: linux-mm, uclinux-dev, gerg, lethal, David Howells, Al Viro,
	stable

Lock i_mmap_mutex for access to the VMA prio list to prevent concurrent access.
Currently, certain parts of the mmap handling are protected by the region
mutex, but not all.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
cc: stable@vger.kernel.org
---

 mm/nommu.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)


diff --git a/mm/nommu.c b/mm/nommu.c
index b982290..ee7e57e 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -696,9 +696,11 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma)
 	if (vma->vm_file) {
 		mapping = vma->vm_file->f_mapping;
 
+		mutex_lock(&mapping->i_mmap_mutex);
 		flush_dcache_mmap_lock(mapping);
 		vma_prio_tree_insert(vma, &mapping->i_mmap);
 		flush_dcache_mmap_unlock(mapping);
+		mutex_unlock(&mapping->i_mmap_mutex);
 	}
 
 	/* add the VMA to the tree */
@@ -760,9 +762,11 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
 	if (vma->vm_file) {
 		mapping = vma->vm_file->f_mapping;
 
+		mutex_lock(&mapping->i_mmap_mutex);
 		flush_dcache_mmap_lock(mapping);
 		vma_prio_tree_remove(vma, &mapping->i_mmap);
 		flush_dcache_mmap_unlock(mapping);
+		mutex_unlock(&mapping->i_mmap_mutex);
 	}
 
 	/* remove from the MM's tree and list */
@@ -2052,6 +2056,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 	high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
 	down_write(&nommu_region_sem);
+	mutex_lock(&inode->i_mapping->i_mmap_mutex);
 
 	/* search for VMAs that fall within the dead zone */
 	vma_prio_tree_foreach(vma, &iter, &inode->i_mapping->i_mmap,
@@ -2059,6 +2064,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 		/* found one - only interested if it's shared out of the page
 		 * cache */
 		if (vma->vm_flags & VM_SHARED) {
+			mutex_unlock(&inode->i_mapping->i_mmap_mutex);
 			up_write(&nommu_region_sem);
 			return -ETXTBSY; /* not quite true, but near enough */
 		}
@@ -2086,6 +2092,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 		}
 	}
 
+	mutex_unlock(&inode->i_mapping->i_mmap_mutex);
 	up_write(&nommu_region_sem);
 	return 0;
 }

--
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] 4+ messages in thread

* [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region()
  2012-02-23 13:50 [PATCH 1/3] NOMMU: Lock i_mmap_mutex for access to the VMA prio list David Howells
@ 2012-02-23 13:50 ` David Howells
  2012-02-23 13:51 ` [PATCH 3/3] NOMMU: Don't need to clear vm_mm when deleting a VMA David Howells
  2012-02-23 13:52 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2012-02-23 13:50 UTC (permalink / raw)
  To: torvalds; +Cc: linux-mm, uclinux-dev, gerg, lethal, David Howells, Al Viro

Merge __put_nommu_region() into put_nommu_region() in the NOMMU mmap code as
that's the only remaining user.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
---

 mm/nommu.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)


diff --git a/mm/nommu.c b/mm/nommu.c
index ee7e57e..d02ee35 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -615,15 +615,15 @@ static void free_page_series(unsigned long from, unsigned long to)
 
 /*
  * release a reference to a region
- * - the caller must hold the region semaphore for writing, which this releases
  * - the region may not have been added to the tree yet, in which case vm_top
  *   will equal vm_start
  */
-static void __put_nommu_region(struct vm_region *region)
-	__releases(nommu_region_sem)
+static void put_nommu_region(struct vm_region *region)
 {
 	kenter("%p{%d}", region, region->vm_usage);
 
+	down_write(&nommu_region_sem);
+
 	BUG_ON(!nommu_region_tree.rb_node);
 
 	if (--region->vm_usage == 0) {
@@ -647,15 +647,6 @@ static void __put_nommu_region(struct vm_region *region)
 }
 
 /*
- * release a reference to a region
- */
-static void put_nommu_region(struct vm_region *region)
-{
-	down_write(&nommu_region_sem);
-	__put_nommu_region(region);
-}
-
-/*
  * update protection on a vma
  */
 static void protect_vma(struct vm_area_struct *vma, unsigned long flags)

--
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] 4+ messages in thread

* [PATCH 3/3] NOMMU: Don't need to clear vm_mm when deleting a VMA
  2012-02-23 13:50 [PATCH 1/3] NOMMU: Lock i_mmap_mutex for access to the VMA prio list David Howells
  2012-02-23 13:50 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
@ 2012-02-23 13:51 ` David Howells
  2012-02-23 13:52 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2012-02-23 13:51 UTC (permalink / raw)
  To: torvalds
  Cc: linux-mm, uclinux-dev, gerg, lethal, David Howells, Al Viro,
	stable

Don't clear vm_mm in a deleted VMA as it's unnecessary and might conceivably
break the filesystem or driver VMA close routine.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
cc: stable@vger.kernel.org
---

 mm/nommu.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)


diff --git a/mm/nommu.c b/mm/nommu.c
index d02ee35..3d39992 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -770,8 +770,6 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
 
 	if (vma->vm_next)
 		vma->vm_next->vm_prev = vma->vm_prev;
-
-	vma->vm_mm = NULL;
 }
 
 /*

--
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] 4+ messages in thread

* Re: [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region()
  2012-02-23 13:50 [PATCH 1/3] NOMMU: Lock i_mmap_mutex for access to the VMA prio list David Howells
  2012-02-23 13:50 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
  2012-02-23 13:51 ` [PATCH 3/3] NOMMU: Don't need to clear vm_mm when deleting a VMA David Howells
@ 2012-02-23 13:52 ` David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2012-02-23 13:52 UTC (permalink / raw)
  To: torvalds; +Cc: dhowells, linux-mm, uclinux-dev, gerg, lethal, Al Viro

David Howells <dhowells@redhat.com> wrote:

> Merge __put_nommu_region() into put_nommu_region() in the NOMMU mmap code as
> that's the only remaining user.
> 
> Reported-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Acked-by: Al Viro <viro@zeniv.linux.org.uk>

Actually, this isn't a bugfix and could wait for the next merge window.

David

--
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] 4+ messages in thread

end of thread, other threads:[~2012-02-23 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-23 13:50 [PATCH 1/3] NOMMU: Lock i_mmap_mutex for access to the VMA prio list David Howells
2012-02-23 13:50 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells
2012-02-23 13:51 ` [PATCH 3/3] NOMMU: Don't need to clear vm_mm when deleting a VMA David Howells
2012-02-23 13:52 ` [PATCH 2/3] NOMMU: Merge __put_nommu_region() into put_nommu_region() David Howells

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).