Commit 96945de5 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] fork.c bits for uClinux

mmuless ports don't need dup_mmap nor allocation of a pgd.

I tried to avoid ifdef-mess as far as possible, and to archive that
I created small wrappers for pgd allocation/freeing and move taking
of the mmap semaphore into dup_mmap from the only caller.  The end
result is just one additiona ifdef.
parent 1310a881
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/security.h> #include <linux/security.h>
#include <linux/futex.h> #include <linux/futex.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/mount.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
...@@ -205,12 +206,14 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) ...@@ -205,12 +206,14 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
return tsk; return tsk;
} }
static inline int dup_mmap(struct mm_struct * mm) #ifdef CONFIG_MMU
static inline int dup_mmap(struct mm_struct * mm, struct mm_struct * oldmm)
{ {
struct vm_area_struct * mpnt, *tmp, **pprev; struct vm_area_struct * mpnt, *tmp, **pprev;
int retval; int retval;
unsigned long charge = 0; unsigned long charge = 0;
down_write(&oldmm->mmap_sem);
flush_cache_mm(current->mm); flush_cache_mm(current->mm);
mm->locked_vm = 0; mm->locked_vm = 0;
mm->mmap = NULL; mm->mmap = NULL;
...@@ -287,11 +290,29 @@ static inline int dup_mmap(struct mm_struct * mm) ...@@ -287,11 +290,29 @@ static inline int dup_mmap(struct mm_struct * mm)
out: out:
flush_tlb_mm(current->mm); flush_tlb_mm(current->mm);
up_write(&oldmm->mmap_sem);
return retval; return retval;
fail_nomem: fail_nomem:
vm_unacct_memory(charge); vm_unacct_memory(charge);
goto out; goto out;
} }
static inline int mm_alloc_pgd(struct mm_struct * mm)
{
mm->pgd = pgd_alloc(mm);
if (unlikely(!mm->pgd))
return -ENOMEM;
return 0;
}
static inline void mm_free_pgd(struct mm_struct * mm)
{
pgd_free(mm->pgd);
}
#else
#define dup_mmap(mm, oldmm) (0)
#define mm_alloc_pgd(mm) (0)
#define mm_free_pgd(mm)
#endif /* CONFIG_MMU */
spinlock_t mmlist_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED; spinlock_t mmlist_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
int mmlist_nr; int mmlist_nr;
...@@ -314,8 +335,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm) ...@@ -314,8 +335,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm)
mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm); mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm);
mm->free_area_cache = TASK_UNMAPPED_BASE; mm->free_area_cache = TASK_UNMAPPED_BASE;
mm->pgd = pgd_alloc(mm); if (likely(!mm_alloc_pgd(mm)))
if (mm->pgd)
return mm; return mm;
free_mm(mm); free_mm(mm);
return NULL; return NULL;
...@@ -344,8 +364,8 @@ struct mm_struct * mm_alloc(void) ...@@ -344,8 +364,8 @@ struct mm_struct * mm_alloc(void)
*/ */
inline void __mmdrop(struct mm_struct *mm) inline void __mmdrop(struct mm_struct *mm)
{ {
if (mm == &init_mm) BUG(); BUG_ON(mm == &init_mm);
pgd_free(mm->pgd); mm_free_pgd(mm);
destroy_context(mm); destroy_context(mm);
free_mm(mm); free_mm(mm);
} }
...@@ -444,10 +464,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk) ...@@ -444,10 +464,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
if (init_new_context(tsk,mm)) if (init_new_context(tsk,mm))
goto free_pt; goto free_pt;
down_write(&oldmm->mmap_sem); retval = dup_mmap(mm, oldmm);
retval = dup_mmap(mm);
up_write(&oldmm->mmap_sem);
if (retval) if (retval)
goto free_pt; goto free_pt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment