mm/sparse.c: fix typo in online_mem_sections
[linux-2.6-microblaze.git] / mm / shmem.c
index b7d84c4..ace53a5 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/swap.h>
 #include <linux/uio.h>
 #include <linux/khugepaged.h>
+#include <linux/hugetlb.h>
 
 #include <asm/tlbflush.h> /* for arch/microblaze update_mmu_cache() */
 
@@ -1649,7 +1650,7 @@ repeat:
 
        if (swap.val) {
                /* Look it up and read it in.. */
-               page = lookup_swap_cache(swap);
+               page = lookup_swap_cache(swap, NULL, 0);
                if (!page) {
                        /* Or update major stats only when swapin succeeds?? */
                        if (fault_type) {
@@ -2207,12 +2208,13 @@ bool shmem_mapping(struct address_space *mapping)
        return mapping->a_ops == &shmem_aops;
 }
 
-int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
-                          pmd_t *dst_pmd,
-                          struct vm_area_struct *dst_vma,
-                          unsigned long dst_addr,
-                          unsigned long src_addr,
-                          struct page **pagep)
+static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
+                                 pmd_t *dst_pmd,
+                                 struct vm_area_struct *dst_vma,
+                                 unsigned long dst_addr,
+                                 unsigned long src_addr,
+                                 bool zeropage,
+                                 struct page **pagep)
 {
        struct inode *inode = file_inode(dst_vma->vm_file);
        struct shmem_inode_info *info = SHMEM_I(inode);
@@ -2235,17 +2237,22 @@ int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
                if (!page)
                        goto out_unacct_blocks;
 
-               page_kaddr = kmap_atomic(page);
-               ret = copy_from_user(page_kaddr, (const void __user *)src_addr,
-                                    PAGE_SIZE);
-               kunmap_atomic(page_kaddr);
-
-               /* fallback to copy_from_user outside mmap_sem */
-               if (unlikely(ret)) {
-                       *pagep = page;
-                       shmem_inode_unacct_blocks(inode, 1);
-                       /* don't free the page */
-                       return -EFAULT;
+               if (!zeropage) {        /* mcopy_atomic */
+                       page_kaddr = kmap_atomic(page);
+                       ret = copy_from_user(page_kaddr,
+                                            (const void __user *)src_addr,
+                                            PAGE_SIZE);
+                       kunmap_atomic(page_kaddr);
+
+                       /* fallback to copy_from_user outside mmap_sem */
+                       if (unlikely(ret)) {
+                               *pagep = page;
+                               shmem_inode_unacct_blocks(inode, 1);
+                               /* don't free the page */
+                               return -EFAULT;
+                       }
+               } else {                /* mfill_zeropage_atomic */
+                       clear_highpage(page);
                }
        } else {
                page = *pagep;
@@ -2311,6 +2318,28 @@ out_unacct_blocks:
        goto out;
 }
 
+int shmem_mcopy_atomic_pte(struct mm_struct *dst_mm,
+                          pmd_t *dst_pmd,
+                          struct vm_area_struct *dst_vma,
+                          unsigned long dst_addr,
+                          unsigned long src_addr,
+                          struct page **pagep)
+{
+       return shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma,
+                                     dst_addr, src_addr, false, pagep);
+}
+
+int shmem_mfill_zeropage_pte(struct mm_struct *dst_mm,
+                            pmd_t *dst_pmd,
+                            struct vm_area_struct *dst_vma,
+                            unsigned long dst_addr)
+{
+       struct page *page = NULL;
+
+       return shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma,
+                                     dst_addr, 0, true, &page);
+}
+
 #ifdef CONFIG_TMPFS
 static const struct inode_operations shmem_symlink_inode_operations;
 static const struct inode_operations shmem_short_symlink_operations;
@@ -3624,7 +3653,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root)
 #define MFD_NAME_PREFIX_LEN (sizeof(MFD_NAME_PREFIX) - 1)
 #define MFD_NAME_MAX_LEN (NAME_MAX - MFD_NAME_PREFIX_LEN)
 
-#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING)
+#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB)
 
 SYSCALL_DEFINE2(memfd_create,
                const char __user *, uname,
@@ -3636,8 +3665,18 @@ SYSCALL_DEFINE2(memfd_create,
        char *name;
        long len;
 
-       if (flags & ~(unsigned int)MFD_ALL_FLAGS)
-               return -EINVAL;
+       if (!(flags & MFD_HUGETLB)) {
+               if (flags & ~(unsigned int)MFD_ALL_FLAGS)
+                       return -EINVAL;
+       } else {
+               /* Sealing not supported in hugetlbfs (MFD_HUGETLB) */
+               if (flags & MFD_ALLOW_SEALING)
+                       return -EINVAL;
+               /* Allow huge page size encoding in flags. */
+               if (flags & ~(unsigned int)(MFD_ALL_FLAGS |
+                               (MFD_HUGE_MASK << MFD_HUGE_SHIFT)))
+                       return -EINVAL;
+       }
 
        /* length includes terminating zero */
        len = strnlen_user(uname, MFD_NAME_MAX_LEN + 1);
@@ -3668,16 +3707,30 @@ SYSCALL_DEFINE2(memfd_create,
                goto err_name;
        }
 
-       file = shmem_file_setup(name, 0, VM_NORESERVE);
+       if (flags & MFD_HUGETLB) {
+               struct user_struct *user = NULL;
+
+               file = hugetlb_file_setup(name, 0, VM_NORESERVE, &user,
+                                       HUGETLB_ANONHUGE_INODE,
+                                       (flags >> MFD_HUGE_SHIFT) &
+                                       MFD_HUGE_MASK);
+       } else
+               file = shmem_file_setup(name, 0, VM_NORESERVE);
        if (IS_ERR(file)) {
                error = PTR_ERR(file);
                goto err_fd;
        }
-       info = SHMEM_I(file_inode(file));
        file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
        file->f_flags |= O_RDWR | O_LARGEFILE;
-       if (flags & MFD_ALLOW_SEALING)
+
+       if (flags & MFD_ALLOW_SEALING) {
+               /*
+                * flags check at beginning of function ensures
+                * this is not a hugetlbfs (MFD_HUGETLB) file.
+                */
+               info = SHMEM_I(file_inode(file));
                info->seals &= ~F_SEAL_SEAL;
+       }
 
        fd_install(fd, file);
        kfree(name);