oops - only non-smp config ready for now
[linux-2.6.git] / mm / mprotect.c
index 5db73dc..05dc342 100644 (file)
@@ -30,8 +30,9 @@ static void change_pte_range(struct mm_struct *mm, pmd_t *pmd,
                unsigned long addr, unsigned long end, pgprot_t newprot)
 {
        pte_t *pte;
+       spinlock_t *ptl;
 
-       pte = pte_offset_map(pmd, addr);
+       pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
        do {
                if (pte_present(*pte)) {
                        pte_t ptent;
@@ -45,7 +46,7 @@ static void change_pte_range(struct mm_struct *mm, pmd_t *pmd,
                        lazy_mmu_prot_update(ptent);
                }
        } while (pte++, addr += PAGE_SIZE, addr != end);
-       pte_unmap(pte - 1);
+       pte_unmap_unlock(pte - 1, ptl);
 }
 
 static inline void change_pmd_range(struct mm_struct *mm, pud_t *pud,
@@ -89,7 +90,6 @@ static void change_protection(struct vm_area_struct *vma,
        BUG_ON(addr >= end);
        pgd = pgd_offset(mm, addr);
        flush_cache_range(vma, addr, end);
-       spin_lock(&mm->page_table_lock);
        do {
                next = pgd_addr_end(addr, end);
                if (pgd_none_or_clear_bad(pgd))
@@ -97,7 +97,6 @@ static void change_protection(struct vm_area_struct *vma,
                change_pud_range(mm, pgd, addr, next, newprot);
        } while (pgd++, addr = next, addr != end);
        flush_tlb_range(vma, start, end);
-       spin_unlock(&mm->page_table_lock);
 }
 
 static int
@@ -126,7 +125,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
         * a MAP_NORESERVE private mapping to writable will now reserve.
         */
        if (newflags & VM_WRITE) {
-               if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_SHARED|VM_HUGETLB))) {
+               if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_SHARED))) {
                        charged = nrpages;
                        if (security_vm_enough_memory(charged))
                                return -ENOMEM;
@@ -170,9 +169,12 @@ success:
        vma->vm_page_prot = newprot;
        if (oldflags & VM_EXEC)
                arch_remove_exec_range(current->mm, old_end);
-       change_protection(vma, start, end, newprot);
-       __vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
-       __vm_stat_account(mm, newflags, vma->vm_file, nrpages);
+       if (is_vm_hugetlb_page(vma))
+               hugetlb_change_protection(vma, start, end, newprot);
+       else
+               change_protection(vma, start, end, newprot);
+       vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
+       vm_stat_account(mm, newflags, vma->vm_file, nrpages);
        return 0;
 
 fail:
@@ -181,8 +183,7 @@ fail:
 }
 
 asmlinkage long
-do_mprotect(struct mm_struct *mm, unsigned long start, size_t len, 
-            unsigned long prot)
+sys_mprotect(unsigned long start, size_t len, unsigned long prot)
 {
        unsigned long vm_flags, nstart, end, tmp, reqprot;
        struct vm_area_struct *vma, *prev;
@@ -213,9 +214,9 @@ do_mprotect(struct mm_struct *mm, unsigned long start, size_t len,
 
        vm_flags = calc_vm_prot_bits(prot);
 
-       down_write(&mm->mmap_sem);
+       down_write(&current->mm->mmap_sem);
 
-       vma = find_vma_prev(mm, start, &prev);
+       vma = find_vma_prev(current->mm, start, &prev);
        error = -ENOMEM;
        if (!vma)
                goto out;
@@ -245,14 +246,10 @@ do_mprotect(struct mm_struct *mm, unsigned long start, size_t len,
 
                /* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
 
-               if (is_vm_hugetlb_page(vma)) {
-                       error = -EACCES;
-                       goto out;
-               }
-
                newflags = vm_flags | (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
 
-               if ((newflags & ~(newflags >> 4)) & 0xf) {
+               /* newflags >> 4 shift VM_MAY% in place of VM_% */
+               if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
                        error = -EACCES;
                        goto out;
                }
@@ -281,11 +278,6 @@ do_mprotect(struct mm_struct *mm, unsigned long start, size_t len,
                }
        }
 out:
-       up_write(&mm->mmap_sem);
+       up_write(&current->mm->mmap_sem);
        return error;
 }
-
-asmlinkage long sys_mprotect(unsigned long start, size_t len, unsigned long prot)
-{
-        return(do_mprotect(current->mm, start, len, prot));
-}