public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NOMMU: add support for Memory Protection Units (MPU)
@ 2009-07-14 14:22 Mike Frysinger
  2009-07-14 16:14 ` Johannes Weiner
  2009-09-16 13:57 ` [PATCH] " Mike Frysinger
  0 siblings, 2 replies; 18+ messages in thread
From: Mike Frysinger @ 2009-07-14 14:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: uclinux-dist-devel, Bernd Schmidt, Bryan Wu, David Howells

From: Bernd Schmidt <bernds_cb1@t-online.de>

Some architectures (like the Blackfin arch) implement some of the
"simpler" features that one would expect out of a MMU such as memory
protection.  In our case, we actually get read/write/exec protection
down to the page boundary so processes can't stomp on each other let
alone the kernel.  There is a performance decrease (which depends greatly
on the workload) however as the hardware/software interaction was not
optimized at design time.

Signed-off-by: Bernd Schmidt <bernds_cb1@t-online.de>
Signed-off-by: Bryan Wu <cooloney@kernel.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: David Howells <dhowells@redhat.com>
---
 kernel/module.c |    5 +++++
 mm/nommu.c      |   25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 0a04983..e1a3dfc 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -47,6 +47,7 @@
 #include <linux/rculist.h>
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
+#include <asm/mmu_context.h>
 #include <linux/license.h>
 #include <asm/sections.h>
 #include <linux/tracepoint.h>
@@ -1519,6 +1520,10 @@ static void free_module(struct module *mod)
 
 	/* Finally, free the core (containing the module structure) */
 	module_free(mod, mod->module_core);
+
+#ifdef CONFIG_MPU
+	update_protections(current->mm);
+#endif
 }
 
 void *__symbol_get(const char *symbol)
diff --git a/mm/nommu.c b/mm/nommu.c
index 53cab10..a0269e5 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -33,6 +33,7 @@
 #include <asm/uaccess.h>
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
+#include <asm/mmu_context.h>
 #include "internal.h"
 
 static inline __attribute__((format(printf, 1, 2)))
@@ -640,11 +641,23 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma)
 	struct vm_area_struct *pvma, **pp;
 	struct address_space *mapping;
 	struct rb_node **p, *parent;
+#ifdef CONFIG_MPU
+	long start;
+#endif
 
 	kenter(",%p", vma);
 
 	BUG_ON(!vma->vm_region);
 
+#ifdef CONFIG_MPU
+	start = vma->vm_start & PAGE_MASK;
+	while (start < vma->vm_end) {
+		protect_page(mm, start, vma->vm_flags);
+		start += PAGE_SIZE;
+	}
+	update_protections(mm);
+#endif
+
 	mm->map_count++;
 	vma->vm_mm = mm;
 
@@ -707,9 +720,21 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
 	struct vm_area_struct **pp;
 	struct address_space *mapping;
 	struct mm_struct *mm = vma->vm_mm;
+#ifdef CONFIG_MPU
+	long start;
+#endif
 
 	kenter("%p", vma);
 
+#ifdef CONFIG_MPU
+	start = vma->vm_start & PAGE_MASK;
+	while (start < vma->vm_end) {
+		protect_page(mm, start, 0);
+		start += PAGE_SIZE;
+	}
+	update_protections(mm);
+#endif
+
 	mm->map_count--;
 	if (mm->mmap_cache == vma)
 		mm->mmap_cache = NULL;
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2009-09-16 13:57 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-14 14:22 [PATCH] NOMMU: add support for Memory Protection Units (MPU) Mike Frysinger
2009-07-14 16:14 ` Johannes Weiner
2009-07-14 16:19   ` Mike Frysinger
2009-07-14 17:14   ` [PATCH v2] " Mike Frysinger
2009-07-14 17:22     ` David Howells
2009-07-14 21:59       ` Bernd Schmidt
2009-07-15 10:31         ` David Howells
2009-07-15 11:18           ` [Uclinux-dist-devel] " Mike Frysinger
2009-07-15 10:37         ` David Howells
2009-07-15 11:12           ` [Uclinux-dist-devel] " Mike Frysinger
2009-07-15 11:45             ` David Howells
2009-07-15 11:55               ` Mike Frysinger
2009-07-15 12:25                 ` David Howells
2009-07-15 12:52                   ` Mike Frysinger
2009-07-15  9:24       ` Paul Mundt
2009-09-14  3:52     ` Mike Frysinger
2009-09-16 10:09       ` David Howells
2009-09-16 13:57 ` [PATCH] " Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox