Commit b634975c authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

[PATCH] ptwalk: zeromap_page_range

Convert zeromap_page_range pagetable walkers to loops using p?d_addr_end.
Remove the redundant flush_tlb_range from afterwards: as its comment
noted, there's already a BUG_ON(!pte_none).
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ccdb8d8d
...@@ -975,113 +975,78 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, ...@@ -975,113 +975,78 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
EXPORT_SYMBOL(get_user_pages); EXPORT_SYMBOL(get_user_pages);
static void zeromap_pte_range(struct mm_struct *mm, pte_t * pte, static int zeromap_pte_range(struct mm_struct *mm, pmd_t *pmd,
unsigned long address, unsigned long addr, unsigned long end, pgprot_t prot)
unsigned long size, pgprot_t prot)
{ {
unsigned long base, end; pte_t *pte;
base = address & PMD_MASK; pte = pte_alloc_map(mm, pmd, addr);
address &= ~PMD_MASK; if (!pte)
end = address + size; return -ENOMEM;
if (end > PMD_SIZE)
end = PMD_SIZE;
do { do {
pte_t zero_pte = pte_wrprotect(mk_pte(ZERO_PAGE(base+address), prot)); pte_t zero_pte = pte_wrprotect(mk_pte(ZERO_PAGE(addr), prot));
BUG_ON(!pte_none(*pte)); BUG_ON(!pte_none(*pte));
set_pte_at(mm, base+address, pte, zero_pte); set_pte_at(mm, addr, pte, zero_pte);
address += PAGE_SIZE; } while (pte++, addr += PAGE_SIZE, addr != end);
pte++; pte_unmap(pte - 1);
} while (address && (address < end)); return 0;
} }
static inline int zeromap_pmd_range(struct mm_struct *mm, pmd_t * pmd, static inline int zeromap_pmd_range(struct mm_struct *mm, pud_t *pud,
unsigned long address, unsigned long size, pgprot_t prot) unsigned long addr, unsigned long end, pgprot_t prot)
{ {
unsigned long base, end; pmd_t *pmd;
unsigned long next;
base = address & PUD_MASK; pmd = pmd_alloc(mm, pud, addr);
address &= ~PUD_MASK; if (!pmd)
end = address + size; return -ENOMEM;
if (end > PUD_SIZE)
end = PUD_SIZE;
do { do {
pte_t * pte = pte_alloc_map(mm, pmd, base + address); next = pmd_addr_end(addr, end);
if (!pte) if (zeromap_pte_range(mm, pmd, addr, next, prot))
return -ENOMEM; return -ENOMEM;
zeromap_pte_range(mm, pte, base + address, end - address, prot); } while (pmd++, addr = next, addr != end);
pte_unmap(pte);
address = (address + PMD_SIZE) & PMD_MASK;
pmd++;
} while (address && (address < end));
return 0; return 0;
} }
static inline int zeromap_pud_range(struct mm_struct *mm, pud_t * pud, static inline int zeromap_pud_range(struct mm_struct *mm, pgd_t *pgd,
unsigned long address, unsigned long addr, unsigned long end, pgprot_t prot)
unsigned long size, pgprot_t prot)
{ {
unsigned long base, end; pud_t *pud;
int error = 0; unsigned long next;
base = address & PGDIR_MASK; pud = pud_alloc(mm, pgd, addr);
address &= ~PGDIR_MASK; if (!pud)
end = address + size; return -ENOMEM;
if (end > PGDIR_SIZE)
end = PGDIR_SIZE;
do { do {
pmd_t * pmd = pmd_alloc(mm, pud, base + address); next = pud_addr_end(addr, end);
error = -ENOMEM; if (zeromap_pmd_range(mm, pud, addr, next, prot))
if (!pmd) return -ENOMEM;
break; } while (pud++, addr = next, addr != end);
error = zeromap_pmd_range(mm, pmd, base + address,
end - address, prot);
if (error)
break;
address = (address + PUD_SIZE) & PUD_MASK;
pud++;
} while (address && (address < end));
return 0; return 0;
} }
int zeromap_page_range(struct vm_area_struct *vma, unsigned long address, int zeromap_page_range(struct vm_area_struct *vma,
unsigned long size, pgprot_t prot) unsigned long addr, unsigned long size, pgprot_t prot)
{ {
int i; pgd_t *pgd;
int error = 0;
pgd_t * pgd;
unsigned long beg = address;
unsigned long end = address + size;
unsigned long next; unsigned long next;
unsigned long end = addr + size;
struct mm_struct *mm = vma->vm_mm; struct mm_struct *mm = vma->vm_mm;
int err;
pgd = pgd_offset(mm, address); BUG_ON(addr >= end);
flush_cache_range(vma, beg, end); pgd = pgd_offset(mm, addr);
BUG_ON(address >= end); flush_cache_range(vma, addr, end);
BUG_ON(end > vma->vm_end);
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
for (i = pgd_index(address); i <= pgd_index(end-1); i++) { do {
pud_t *pud = pud_alloc(mm, pgd, address); next = pgd_addr_end(addr, end);
error = -ENOMEM; err = zeromap_pud_range(mm, pgd, addr, next, prot);
if (!pud) if (err)
break;
next = (address + PGDIR_SIZE) & PGDIR_MASK;
if (next <= beg || next > end)
next = end;
error = zeromap_pud_range(mm, pud, address,
next - address, prot);
if (error)
break; break;
address = next; } while (pgd++, addr = next, addr != end);
pgd++;
}
/*
* Why flush? zeromap_pte_range has a BUG_ON for !pte_none()
*/
flush_tlb_range(vma, beg, end);
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
return error; return err;
} }
/* /*
......
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