Merge branch 'hwpoison-2.6.32' of git://git.kernel.org/pub/scm/linux/kernel/git/ak...
[safe/jmp/linux-2.6] / mm / mmap.c
index 22dff49..73f5e4b 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -27,7 +27,6 @@
 #include <linux/mount.h>
 #include <linux/mempolicy.h>
 #include <linux/rmap.h>
-#include <linux/ksm.h>
 #include <linux/mmu_notifier.h>
 #include <linux/perf_event.h>
 
@@ -571,9 +570,9 @@ again:                      remove_next = 1 + (end > next->vm_end);
 
        /*
         * When changing only vma->vm_end, we don't really need
-        * anon_vma lock: but is that case worth optimizing out?
+        * anon_vma lock.
         */
-       if (vma->anon_vma)
+       if (vma->anon_vma && (insert || importer || start != vma->vm_start))
                anon_vma = vma->anon_vma;
        if (anon_vma) {
                spin_lock(&anon_vma->lock);
@@ -950,6 +949,24 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
        if (mm->map_count > sysctl_max_map_count)
                return -ENOMEM;
 
+       if (flags & MAP_HUGETLB) {
+               struct user_struct *user = NULL;
+               if (file)
+                       return -EINVAL;
+
+               /*
+                * VM_NORESERVE is used because the reservations will be
+                * taken when vm_ops->mmap() is called
+                * A dummy user value is used because we are not locking
+                * memory so no accounting is necessary
+                */
+               len = ALIGN(len, huge_page_size(&default_hstate));
+               file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
+                                               &user, HUGETLB_ANONHUGE_INODE);
+               if (IS_ERR(file))
+                       return PTR_ERR(file);
+       }
+
        /* Obtain the address to map to. we verify (or select) it and ensure
         * that it represents a valid section of the address space.
         */
@@ -964,11 +981,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
        vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
                        mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
 
-       if (flags & MAP_LOCKED) {
+       if (flags & MAP_LOCKED)
                if (!can_do_mlock())
                        return -EPERM;
-               vm_flags |= VM_LOCKED;
-       }
 
        /* mlock MCL_FUTURE? */
        if (vm_flags & VM_LOCKED) {
@@ -1194,21 +1209,21 @@ munmap_back:
                        goto unmap_and_free_vma;
                if (vm_flags & VM_EXECUTABLE)
                        added_exe_file_vma(mm);
+
+               /* Can addr have changed??
+                *
+                * Answer: Yes, several device drivers can do it in their
+                *         f_op->mmap method. -DaveM
+                */
+               addr = vma->vm_start;
+               pgoff = vma->vm_pgoff;
+               vm_flags = vma->vm_flags;
        } else if (vm_flags & VM_SHARED) {
                error = shmem_zero_setup(vma);
                if (error)
                        goto free_vma;
        }
 
-       /* Can addr have changed??
-        *
-        * Answer: Yes, several device drivers can do it in their
-        *         f_op->mmap method. -DaveM
-        */
-       addr = vma->vm_start;
-       pgoff = vma->vm_pgoff;
-       vm_flags = vma->vm_flags;
-
        if (vma_wants_writenotify(vma))
                vma->vm_page_prot = vm_get_page_prot(vm_flags & ~VM_SHARED);
 
@@ -2267,7 +2282,7 @@ static void special_mapping_close(struct vm_area_struct *vma)
 {
 }
 
-static struct vm_operations_struct special_mapping_vmops = {
+static const struct vm_operations_struct special_mapping_vmops = {
        .close = special_mapping_close,
        .fault = special_mapping_fault,
 };