Commit c9cfcddf authored by Linus Torvalds's avatar Linus Torvalds

VM: add common helper function to create the page tables

This logic was duplicated four times, for no good reason.
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4168f7a3
...@@ -306,9 +306,6 @@ void install_arg_page(struct vm_area_struct *vma, ...@@ -306,9 +306,6 @@ void install_arg_page(struct vm_area_struct *vma,
struct page *page, unsigned long address) struct page *page, unsigned long address)
{ {
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
pgd_t * pgd;
pud_t * pud;
pmd_t * pmd;
pte_t * pte; pte_t * pte;
spinlock_t *ptl; spinlock_t *ptl;
...@@ -316,14 +313,7 @@ void install_arg_page(struct vm_area_struct *vma, ...@@ -316,14 +313,7 @@ void install_arg_page(struct vm_area_struct *vma,
goto out; goto out;
flush_dcache_page(page); flush_dcache_page(page);
pgd = pgd_offset(mm, address); pte = get_locked_pte(mm, address, &ptl);
pud = pud_alloc(mm, pgd, address);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, address);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, address, &ptl);
if (!pte) if (!pte)
goto out; goto out;
if (!pte_none(*pte)) { if (!pte_none(*pte)) {
......
...@@ -742,6 +742,8 @@ struct shrinker; ...@@ -742,6 +742,8 @@ struct shrinker;
extern struct shrinker *set_shrinker(int, shrinker_t); extern struct shrinker *set_shrinker(int, shrinker_t);
extern void remove_shrinker(struct shrinker *shrinker); extern void remove_shrinker(struct shrinker *shrinker);
extern pte_t *FASTCALL(get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl));
int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address); int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address); int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address); int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address);
......
...@@ -55,20 +55,10 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -55,20 +55,10 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma,
pgoff_t size; pgoff_t size;
int err = -ENOMEM; int err = -ENOMEM;
pte_t *pte; pte_t *pte;
pmd_t *pmd;
pud_t *pud;
pgd_t *pgd;
pte_t pte_val; pte_t pte_val;
spinlock_t *ptl; spinlock_t *ptl;
pgd = pgd_offset(mm, addr); pte = get_locked_pte(mm, addr, &ptl);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
if (!pte) if (!pte)
goto out; goto out;
...@@ -110,20 +100,10 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -110,20 +100,10 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma,
{ {
int err = -ENOMEM; int err = -ENOMEM;
pte_t *pte; pte_t *pte;
pmd_t *pmd;
pud_t *pud;
pgd_t *pgd;
pte_t pte_val; pte_t pte_val;
spinlock_t *ptl; spinlock_t *ptl;
pgd = pgd_offset(mm, addr); pte = get_locked_pte(mm, addr, &ptl);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
if (!pte) if (!pte)
goto out; goto out;
......
...@@ -1146,6 +1146,18 @@ int zeromap_page_range(struct vm_area_struct *vma, ...@@ -1146,6 +1146,18 @@ int zeromap_page_range(struct vm_area_struct *vma,
return err; return err;
} }
pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
{
pgd_t * pgd = pgd_offset(mm, addr);
pud_t * pud = pud_alloc(mm, pgd, addr);
if (pud) {
pmd_t * pmd = pmd_alloc(mm, pgd, addr);
if (pmd)
return pte_alloc_map_lock(mm, pmd, addr, ptl);
}
return NULL;
}
/* /*
* This is the old fallback for page remapping. * This is the old fallback for page remapping.
* *
...@@ -1156,10 +1168,7 @@ int zeromap_page_range(struct vm_area_struct *vma, ...@@ -1156,10 +1168,7 @@ int zeromap_page_range(struct vm_area_struct *vma,
static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot) static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot)
{ {
int retval; int retval;
pgd_t * pgd; pte_t *pte;
pud_t * pud;
pmd_t * pmd;
pte_t * pte;
spinlock_t *ptl; spinlock_t *ptl;
retval = -EINVAL; retval = -EINVAL;
...@@ -1167,14 +1176,7 @@ static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *pa ...@@ -1167,14 +1176,7 @@ static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *pa
goto out; goto out;
retval = -ENOMEM; retval = -ENOMEM;
flush_dcache_page(page); flush_dcache_page(page);
pgd = pgd_offset(mm, addr); pte = get_locked_pte(mm, addr, &ptl);
pud = pud_alloc(mm, pgd, addr);
if (!pud)
goto out;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
goto out;
pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
if (!pte) if (!pte)
goto out; goto out;
retval = -EBUSY; retval = -EBUSY;
......
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