Skip to content

Commit

Permalink
nommu: add support for Memory Protection Units (MPU)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
Acked-by: David Howells <[email protected]>
Acked-by: Greg Ungerer <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
bernds authored and torvalds committed Sep 22, 2009
1 parent 02e87d1 commit eb8cdec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -1535,6 +1536,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)
Expand Down
21 changes: 21 additions & 0 deletions mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -622,6 +623,22 @@ static void put_nommu_region(struct vm_region *region)
__put_nommu_region(region);
}

/*
* update protection on a vma
*/
static void protect_vma(struct vm_area_struct *vma, unsigned long flags)
{
#ifdef CONFIG_MPU
struct mm_struct *mm = vma->vm_mm;
long start = vma->vm_start & PAGE_MASK;
while (start < vma->vm_end) {
protect_page(mm, start, flags);
start += PAGE_SIZE;
}
update_protections(mm);
#endif
}

/*
* add a VMA into a process's mm_struct in the appropriate place in the list
* and tree and add to the address space's page tree also if not an anonymous
Expand All @@ -641,6 +658,8 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma)
mm->map_count++;
vma->vm_mm = mm;

protect_vma(vma, vma->vm_flags);

/* add the VMA to the mapping */
if (vma->vm_file) {
mapping = vma->vm_file->f_mapping;
Expand Down Expand Up @@ -703,6 +722,8 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)

kenter("%p", vma);

protect_vma(vma, 0);

mm->map_count--;
if (mm->mmap_cache == vma)
mm->mmap_cache = NULL;
Expand Down

0 comments on commit eb8cdec

Please sign in to comment.