net: phy: mscc: do not access the MDIO bus lock directly
[platform/kernel/linux-rpi.git] / mm / vmalloc.c
index 6b8eeb0..3091c2c 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/llist.h>
 #include <linux/bitops.h>
 #include <linux/rbtree_augmented.h>
+#include <linux/overflow.h>
 
 #include <linux/uaccess.h>
 #include <asm/tlbflush.h>
@@ -68,7 +69,8 @@ static void free_work(struct work_struct *w)
 
 /*** Page table manipulation functions ***/
 
-static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
+static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+                            pgtbl_mod_mask *mask)
 {
        pte_t *pte;
 
@@ -77,73 +79,118 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
                pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
                WARN_ON(!pte_none(ptent) && !pte_present(ptent));
        } while (pte++, addr += PAGE_SIZE, addr != end);
+       *mask |= PGTBL_PTE_MODIFIED;
 }
 
-static void vunmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end)
+static void vunmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
+                            pgtbl_mod_mask *mask)
 {
        pmd_t *pmd;
        unsigned long next;
+       int cleared;
 
        pmd = pmd_offset(pud, addr);
        do {
                next = pmd_addr_end(addr, end);
-               if (pmd_clear_huge(pmd))
+
+               cleared = pmd_clear_huge(pmd);
+               if (cleared || pmd_bad(*pmd))
+                       *mask |= PGTBL_PMD_MODIFIED;
+
+               if (cleared)
                        continue;
                if (pmd_none_or_clear_bad(pmd))
                        continue;
-               vunmap_pte_range(pmd, addr, next);
+               vunmap_pte_range(pmd, addr, next, mask);
        } while (pmd++, addr = next, addr != end);
 }
 
-static void vunmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end)
+static void vunmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
+                            pgtbl_mod_mask *mask)
 {
        pud_t *pud;
        unsigned long next;
+       int cleared;
 
        pud = pud_offset(p4d, addr);
        do {
                next = pud_addr_end(addr, end);
-               if (pud_clear_huge(pud))
+
+               cleared = pud_clear_huge(pud);
+               if (cleared || pud_bad(*pud))
+                       *mask |= PGTBL_PUD_MODIFIED;
+
+               if (cleared)
                        continue;
                if (pud_none_or_clear_bad(pud))
                        continue;
-               vunmap_pmd_range(pud, addr, next);
+               vunmap_pmd_range(pud, addr, next, mask);
        } while (pud++, addr = next, addr != end);
 }
 
-static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end)
+static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
+                            pgtbl_mod_mask *mask)
 {
        p4d_t *p4d;
        unsigned long next;
+       int cleared;
 
        p4d = p4d_offset(pgd, addr);
        do {
                next = p4d_addr_end(addr, end);
-               if (p4d_clear_huge(p4d))
+
+               cleared = p4d_clear_huge(p4d);
+               if (cleared || p4d_bad(*p4d))
+                       *mask |= PGTBL_P4D_MODIFIED;
+
+               if (cleared)
                        continue;
                if (p4d_none_or_clear_bad(p4d))
                        continue;
-               vunmap_pud_range(p4d, addr, next);
+               vunmap_pud_range(p4d, addr, next, mask);
        } while (p4d++, addr = next, addr != end);
 }
 
-static void vunmap_page_range(unsigned long addr, unsigned long end)
+/**
+ * unmap_kernel_range_noflush - unmap kernel VM area
+ * @start: start of the VM area to unmap
+ * @size: size of the VM area to unmap
+ *
+ * Unmap PFN_UP(@size) pages at @addr.  The VM area @addr and @size specify
+ * should have been allocated using get_vm_area() and its friends.
+ *
+ * NOTE:
+ * This function does NOT do any cache flushing.  The caller is responsible
+ * for calling flush_cache_vunmap() on to-be-mapped areas before calling this
+ * function and flush_tlb_kernel_range() after.
+ */
+void unmap_kernel_range_noflush(unsigned long start, unsigned long size)
 {
-       pgd_t *pgd;
+       unsigned long end = start + size;
        unsigned long next;
+       pgd_t *pgd;
+       unsigned long addr = start;
+       pgtbl_mod_mask mask = 0;
 
        BUG_ON(addr >= end);
+       start = addr;
        pgd = pgd_offset_k(addr);
        do {
                next = pgd_addr_end(addr, end);
+               if (pgd_bad(*pgd))
+                       mask |= PGTBL_PGD_MODIFIED;
                if (pgd_none_or_clear_bad(pgd))
                        continue;
-               vunmap_p4d_range(pgd, addr, next);
+               vunmap_p4d_range(pgd, addr, next, &mask);
        } while (pgd++, addr = next, addr != end);
+
+       if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
+               arch_sync_kernel_mappings(start, end);
 }
 
 static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
-               unsigned long end, pgprot_t prot, struct page **pages, int *nr)
+               unsigned long end, pgprot_t prot, struct page **pages, int *nr,
+               pgtbl_mod_mask *mask)
 {
        pte_t *pte;
 
@@ -152,7 +199,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
         * callers keep track of where we're up to.
         */
 
-       pte = pte_alloc_kernel(pmd, addr);
+       pte = pte_alloc_kernel_track(pmd, addr, mask);
        if (!pte)
                return -ENOMEM;
        do {
@@ -165,94 +212,117 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
                set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
                (*nr)++;
        } while (pte++, addr += PAGE_SIZE, addr != end);
+       *mask |= PGTBL_PTE_MODIFIED;
        return 0;
 }
 
 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
-               unsigned long end, pgprot_t prot, struct page **pages, int *nr)
+               unsigned long end, pgprot_t prot, struct page **pages, int *nr,
+               pgtbl_mod_mask *mask)
 {
        pmd_t *pmd;
        unsigned long next;
 
-       pmd = pmd_alloc(&init_mm, pud, addr);
+       pmd = pmd_alloc_track(&init_mm, pud, addr, mask);
        if (!pmd)
                return -ENOMEM;
        do {
                next = pmd_addr_end(addr, end);
-               if (vmap_pte_range(pmd, addr, next, prot, pages, nr))
+               if (vmap_pte_range(pmd, addr, next, prot, pages, nr, mask))
                        return -ENOMEM;
        } while (pmd++, addr = next, addr != end);
        return 0;
 }
 
 static int vmap_pud_range(p4d_t *p4d, unsigned long addr,
-               unsigned long end, pgprot_t prot, struct page **pages, int *nr)
+               unsigned long end, pgprot_t prot, struct page **pages, int *nr,
+               pgtbl_mod_mask *mask)
 {
        pud_t *pud;
        unsigned long next;
 
-       pud = pud_alloc(&init_mm, p4d, addr);
+       pud = pud_alloc_track(&init_mm, p4d, addr, mask);
        if (!pud)
                return -ENOMEM;
        do {
                next = pud_addr_end(addr, end);
-               if (vmap_pmd_range(pud, addr, next, prot, pages, nr))
+               if (vmap_pmd_range(pud, addr, next, prot, pages, nr, mask))
                        return -ENOMEM;
        } while (pud++, addr = next, addr != end);
        return 0;
 }
 
 static int vmap_p4d_range(pgd_t *pgd, unsigned long addr,
-               unsigned long end, pgprot_t prot, struct page **pages, int *nr)
+               unsigned long end, pgprot_t prot, struct page **pages, int *nr,
+               pgtbl_mod_mask *mask)
 {
        p4d_t *p4d;
        unsigned long next;
 
-       p4d = p4d_alloc(&init_mm, pgd, addr);
+       p4d = p4d_alloc_track(&init_mm, pgd, addr, mask);
        if (!p4d)
                return -ENOMEM;
        do {
                next = p4d_addr_end(addr, end);
-               if (vmap_pud_range(p4d, addr, next, prot, pages, nr))
+               if (vmap_pud_range(p4d, addr, next, prot, pages, nr, mask))
                        return -ENOMEM;
        } while (p4d++, addr = next, addr != end);
        return 0;
 }
 
-/*
- * Set up page tables in kva (addr, end). The ptes shall have prot "prot", and
- * will have pfns corresponding to the "pages" array.
+/**
+ * map_kernel_range_noflush - map kernel VM area with the specified pages
+ * @addr: start of the VM area to map
+ * @size: size of the VM area to map
+ * @prot: page protection flags to use
+ * @pages: pages to map
  *
- * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
+ * Map PFN_UP(@size) pages at @addr.  The VM area @addr and @size specify should
+ * have been allocated using get_vm_area() and its friends.
+ *
+ * NOTE:
+ * This function does NOT do any cache flushing.  The caller is responsible for
+ * calling flush_cache_vmap() on to-be-mapped areas before calling this
+ * function.
+ *
+ * RETURNS:
+ * 0 on success, -errno on failure.
  */
-static int vmap_page_range_noflush(unsigned long start, unsigned long end,
-                                  pgprot_t prot, struct page **pages)
+int map_kernel_range_noflush(unsigned long addr, unsigned long size,
+                            pgprot_t prot, struct page **pages)
 {
-       pgd_t *pgd;
+       unsigned long start = addr;
+       unsigned long end = addr + size;
        unsigned long next;
-       unsigned long addr = start;
+       pgd_t *pgd;
        int err = 0;
        int nr = 0;
+       pgtbl_mod_mask mask = 0;
 
        BUG_ON(addr >= end);
        pgd = pgd_offset_k(addr);
        do {
                next = pgd_addr_end(addr, end);
-               err = vmap_p4d_range(pgd, addr, next, prot, pages, &nr);
+               if (pgd_bad(*pgd))
+                       mask |= PGTBL_PGD_MODIFIED;
+               err = vmap_p4d_range(pgd, addr, next, prot, pages, &nr, &mask);
                if (err)
                        return err;
        } while (pgd++, addr = next, addr != end);
 
-       return nr;
+       if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
+               arch_sync_kernel_mappings(start, end);
+
+       return 0;
 }
 
-static int vmap_page_range(unsigned long start, unsigned long end,
-                          pgprot_t prot, struct page **pages)
+int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,
+               struct page **pages)
 {
        int ret;
 
-       ret = vmap_page_range_noflush(start, end, prot, pages);
-       flush_cache_vmap(start, end);
+       ret = map_kernel_range_noflush(start, size, prot, pages);
+       flush_cache_vmap(start, start + size);
        return ret;
 }
 
@@ -1222,14 +1292,6 @@ int unregister_vmap_purge_notifier(struct notifier_block *nb)
 EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);
 
 /*
- * Clear the pagetable entries of a given vmap_area
- */
-static void unmap_vmap_area(struct vmap_area *va)
-{
-       vunmap_page_range(va->va_start, va->va_end);
-}
-
-/*
  * lazy_max_pages is the maximum amount of virtual address space we gather up
  * before attempting to purge with a TLB flush.
  *
@@ -1292,12 +1354,6 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end)
                return false;
 
        /*
-        * First make sure the mappings are removed from all page-tables
-        * before they are freed.
-        */
-       vmalloc_sync_unmappings();
-
-       /*
         * TODO: to calculate a flush range without looping.
         * The list can be up to lazy_max_pages() elements.
         */
@@ -1390,7 +1446,7 @@ static void free_vmap_area_noflush(struct vmap_area *va)
 static void free_unmap_vmap_area(struct vmap_area *va)
 {
        flush_cache_vunmap(va->va_start, va->va_end);
-       unmap_vmap_area(va);
+       unmap_kernel_range_noflush(va->va_start, va->va_end - va->va_start);
        if (debug_pagealloc_enabled_static())
                flush_tlb_kernel_range(va->va_start, va->va_end);
 
@@ -1664,7 +1720,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
        return vaddr;
 }
 
-static void vb_free(const void *addr, unsigned long size)
+static void vb_free(unsigned long addr, unsigned long size)
 {
        unsigned long offset;
        unsigned long vb_idx;
@@ -1674,24 +1730,22 @@ static void vb_free(const void *addr, unsigned long size)
        BUG_ON(offset_in_page(size));
        BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
 
-       flush_cache_vunmap((unsigned long)addr, (unsigned long)addr + size);
+       flush_cache_vunmap(addr, addr + size);
 
        order = get_order(size);
 
-       offset = (unsigned long)addr & (VMAP_BLOCK_SIZE - 1);
-       offset >>= PAGE_SHIFT;
+       offset = (addr & (VMAP_BLOCK_SIZE - 1)) >> PAGE_SHIFT;
 
-       vb_idx = addr_to_vb_idx((unsigned long)addr);
+       vb_idx = addr_to_vb_idx(addr);
        rcu_read_lock();
        vb = radix_tree_lookup(&vmap_block_tree, vb_idx);
        rcu_read_unlock();
        BUG_ON(!vb);
 
-       vunmap_page_range((unsigned long)addr, (unsigned long)addr + size);
+       unmap_kernel_range_noflush(addr, size);
 
        if (debug_pagealloc_enabled_static())
-               flush_tlb_kernel_range((unsigned long)addr,
-                                       (unsigned long)addr + size);
+               flush_tlb_kernel_range(addr, addr + size);
 
        spin_lock(&vb->lock);
 
@@ -1791,7 +1845,7 @@ void vm_unmap_ram(const void *mem, unsigned int count)
 
        if (likely(count <= VMAP_MAX_ALLOC)) {
                debug_check_no_locks_freed(mem, size);
-               vb_free(mem, size);
+               vb_free(addr, size);
                return;
        }
 
@@ -1818,7 +1872,7 @@ EXPORT_SYMBOL(vm_unmap_ram);
  *
  * Returns: a pointer to the address that has been mapped, or %NULL on failure
  */
-void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t prot)
+void *vm_map_ram(struct page **pages, unsigned int count, int node)
 {
        unsigned long size = (unsigned long)count << PAGE_SHIFT;
        unsigned long addr;
@@ -1842,7 +1896,7 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t pro
 
        kasan_unpoison_vmalloc(mem, size);
 
-       if (vmap_page_range(addr, addr + size, prot, pages) < 0) {
+       if (map_kernel_range(addr, size, PAGE_KERNEL, pages) < 0) {
                vm_unmap_ram(mem, count);
                return NULL;
        }
@@ -1987,51 +2041,6 @@ void __init vmalloc_init(void)
 }
 
 /**
- * map_kernel_range_noflush - map kernel VM area with the specified pages
- * @addr: start of the VM area to map
- * @size: size of the VM area to map
- * @prot: page protection flags to use
- * @pages: pages to map
- *
- * Map PFN_UP(@size) pages at @addr.  The VM area @addr and @size
- * specify should have been allocated using get_vm_area() and its
- * friends.
- *
- * NOTE:
- * This function does NOT do any cache flushing.  The caller is
- * responsible for calling flush_cache_vmap() on to-be-mapped areas
- * before calling this function.
- *
- * RETURNS:
- * The number of pages mapped on success, -errno on failure.
- */
-int map_kernel_range_noflush(unsigned long addr, unsigned long size,
-                            pgprot_t prot, struct page **pages)
-{
-       return vmap_page_range_noflush(addr, addr + size, prot, pages);
-}
-
-/**
- * unmap_kernel_range_noflush - unmap kernel VM area
- * @addr: start of the VM area to unmap
- * @size: size of the VM area to unmap
- *
- * Unmap PFN_UP(@size) pages at @addr.  The VM area @addr and @size
- * specify should have been allocated using get_vm_area() and its
- * friends.
- *
- * NOTE:
- * This function does NOT do any cache flushing.  The caller is
- * responsible for calling flush_cache_vunmap() on to-be-mapped areas
- * before calling this function and flush_tlb_kernel_range() after.
- */
-void unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
-{
-       vunmap_page_range(addr, addr + size);
-}
-EXPORT_SYMBOL_GPL(unmap_kernel_range_noflush);
-
-/**
  * unmap_kernel_range - unmap kernel VM area and flush cache and TLB
  * @addr: start of the VM area to unmap
  * @size: size of the VM area to unmap
@@ -2044,22 +2053,9 @@ void unmap_kernel_range(unsigned long addr, unsigned long size)
        unsigned long end = addr + size;
 
        flush_cache_vunmap(addr, end);
-       vunmap_page_range(addr, end);
+       unmap_kernel_range_noflush(addr, size);
        flush_tlb_kernel_range(addr, end);
 }
-EXPORT_SYMBOL_GPL(unmap_kernel_range);
-
-int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page **pages)
-{
-       unsigned long addr = (unsigned long)area->addr;
-       unsigned long end = addr + get_vm_area_size(area);
-       int err;
-
-       err = vmap_page_range(addr, end, prot, pages);
-
-       return err > 0 ? 0 : err;
-}
-EXPORT_SYMBOL_GPL(map_vm_area);
 
 static inline void setup_vmalloc_vm_locked(struct vm_struct *vm,
        struct vmap_area *va, unsigned long flags, const void *caller)
@@ -2127,14 +2123,6 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
        return area;
 }
 
-struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
-                               unsigned long start, unsigned long end)
-{
-       return __get_vm_area_node(size, 1, flags, start, end, NUMA_NO_NODE,
-                                 GFP_KERNEL, __builtin_return_address(0));
-}
-EXPORT_SYMBOL_GPL(__get_vm_area);
-
 struct vm_struct *__get_vm_area_caller(unsigned long size, unsigned long flags,
                                       unsigned long start, unsigned long end,
                                       const void *caller)
@@ -2329,7 +2317,7 @@ static inline void __vfree_deferred(const void *addr)
         * Use raw_cpu_ptr() because this can be called from preemptible
         * context. Preemption is absolutely fine here, because the llist_add()
         * implementation is lockless, so it works even if we are adding to
-        * nother cpu's list.  schedule_work() should be fine with this too.
+        * another cpu's list. schedule_work() should be fine with this too.
         */
        struct vfree_deferred *p = raw_cpu_ptr(&vfree_deferred);
 
@@ -2440,7 +2428,8 @@ void *vmap(struct page **pages, unsigned int count,
        if (!area)
                return NULL;
 
-       if (map_vm_area(area, prot, pages)) {
+       if (map_kernel_range((unsigned long)area->addr, size, pgprot_nx(prot),
+                       pages) < 0) {
                vunmap(area->addr);
                return NULL;
        }
@@ -2449,9 +2438,6 @@ void *vmap(struct page **pages, unsigned int count,
 }
 EXPORT_SYMBOL(vmap);
 
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-                           gfp_t gfp_mask, pgprot_t prot,
-                           int node, const void *caller);
 static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
                                 pgprot_t prot, int node)
 {
@@ -2469,7 +2455,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
        /* Please note that the recursion is strictly bounded. */
        if (array_size > PAGE_SIZE) {
                pages = __vmalloc_node(array_size, 1, nested_gfp|highmem_mask,
-                               PAGE_KERNEL, node, area->caller);
+                               node, area->caller);
        } else {
                pages = kmalloc_node(array_size, nested_gfp, node);
        }
@@ -2503,8 +2489,10 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
        }
        atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
 
-       if (map_vm_area(area, prot, pages))
+       if (map_kernel_range((unsigned long)area->addr, get_vm_area_size(area),
+                       prot, pages) < 0)
                goto fail;
+
        return area->addr;
 
 fail:
@@ -2572,27 +2560,16 @@ fail:
        return NULL;
 }
 
-/*
- * This is only for performance analysis of vmalloc and stress purpose.
- * It is required by vmalloc test module, therefore do not use it other
- * than that.
- */
-#ifdef CONFIG_TEST_VMALLOC_MODULE
-EXPORT_SYMBOL_GPL(__vmalloc_node_range);
-#endif
-
 /**
  * __vmalloc_node - allocate virtually contiguous memory
  * @size:          allocation size
  * @align:         desired alignment
  * @gfp_mask:      flags for the page level allocator
- * @prot:          protection mask for the allocated pages
  * @node:          node to use for allocation or NUMA_NO_NODE
  * @caller:        caller's return address
  *
- * Allocate enough pages to cover @size from the page level
- * allocator with @gfp_mask flags.  Map them into contiguous
- * kernel virtual space, using a pagetable protection of @prot.
+ * Allocate enough pages to cover @size from the page level allocator with
+ * @gfp_mask flags.  Map them into contiguous kernel virtual space.
  *
  * Reclaim modifiers in @gfp_mask - __GFP_NORETRY, __GFP_RETRY_MAYFAIL
  * and __GFP_NOFAIL are not supported
@@ -2602,35 +2579,28 @@ EXPORT_SYMBOL_GPL(__vmalloc_node_range);
  *
  * Return: pointer to the allocated memory or %NULL on error
  */
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-                           gfp_t gfp_mask, pgprot_t prot,
-                           int node, const void *caller)
+void *__vmalloc_node(unsigned long size, unsigned long align,
+                           gfp_t gfp_mask, int node, const void *caller)
 {
        return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
-                               gfp_mask, prot, 0, node, caller);
+                               gfp_mask, PAGE_KERNEL, 0, node, caller);
 }
+/*
+ * This is only for performance analysis of vmalloc and stress purpose.
+ * It is required by vmalloc test module, therefore do not use it other
+ * than that.
+ */
+#ifdef CONFIG_TEST_VMALLOC_MODULE
+EXPORT_SYMBOL_GPL(__vmalloc_node);
+#endif
 
-void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
+void *__vmalloc(unsigned long size, gfp_t gfp_mask)
 {
-       return __vmalloc_node(size, 1, gfp_mask, prot, NUMA_NO_NODE,
+       return __vmalloc_node(size, 1, gfp_mask, NUMA_NO_NODE,
                                __builtin_return_address(0));
 }
 EXPORT_SYMBOL(__vmalloc);
 
-static inline void *__vmalloc_node_flags(unsigned long size,
-                                       int node, gfp_t flags)
-{
-       return __vmalloc_node(size, 1, flags, PAGE_KERNEL,
-                                       node, __builtin_return_address(0));
-}
-
-
-void *__vmalloc_node_flags_caller(unsigned long size, int node, gfp_t flags,
-                                 void *caller)
-{
-       return __vmalloc_node(size, 1, flags, PAGE_KERNEL, node, caller);
-}
-
 /**
  * vmalloc - allocate virtually contiguous memory
  * @size:    allocation size
@@ -2645,8 +2615,8 @@ void *__vmalloc_node_flags_caller(unsigned long size, int node, gfp_t flags,
  */
 void *vmalloc(unsigned long size)
 {
-       return __vmalloc_node_flags(size, NUMA_NO_NODE,
-                                   GFP_KERNEL);
+       return __vmalloc_node(size, 1, GFP_KERNEL, NUMA_NO_NODE,
+                               __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vmalloc);
 
@@ -2665,8 +2635,8 @@ EXPORT_SYMBOL(vmalloc);
  */
 void *vzalloc(unsigned long size)
 {
-       return __vmalloc_node_flags(size, NUMA_NO_NODE,
-                               GFP_KERNEL | __GFP_ZERO);
+       return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_ZERO, NUMA_NO_NODE,
+                               __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vzalloc);
 
@@ -2703,8 +2673,8 @@ EXPORT_SYMBOL(vmalloc_user);
  */
 void *vmalloc_node(unsigned long size, int node)
 {
-       return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL,
-                                       node, __builtin_return_address(0));
+       return __vmalloc_node(size, 1, GFP_KERNEL, node,
+                       __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vmalloc_node);
 
@@ -2717,39 +2687,16 @@ EXPORT_SYMBOL(vmalloc_node);
  * allocator and map them into contiguous kernel virtual space.
  * The memory allocated is set to zero.
  *
- * For tight control over page level allocator and protection flags
- * use __vmalloc_node() instead.
- *
  * Return: pointer to the allocated memory or %NULL on error
  */
 void *vzalloc_node(unsigned long size, int node)
 {
-       return __vmalloc_node_flags(size, node,
-                        GFP_KERNEL | __GFP_ZERO);
+       return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_ZERO, node,
+                               __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vzalloc_node);
 
 /**
- * vmalloc_user_node_flags - allocate memory for userspace on a specific node
- * @size: allocation size
- * @node: numa node
- * @flags: flags for the page level allocator
- *
- * The resulting memory area is zeroed so it can be mapped to userspace
- * without leaking data.
- *
- * Return: pointer to the allocated memory or %NULL on error
- */
-void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
-{
-       return __vmalloc_node_range(size, SHMLBA,  VMALLOC_START, VMALLOC_END,
-                                   flags | __GFP_ZERO, PAGE_KERNEL,
-                                   VM_USERMAP, node,
-                                   __builtin_return_address(0));
-}
-EXPORT_SYMBOL(vmalloc_user_node_flags);
-
-/**
  * vmalloc_exec - allocate virtually contiguous, executable memory
  * @size:        allocation size
  *
@@ -2792,8 +2739,8 @@ void *vmalloc_exec(unsigned long size)
  */
 void *vmalloc_32(unsigned long size)
 {
-       return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
-                             NUMA_NO_NODE, __builtin_return_address(0));
+       return __vmalloc_node(size, 1, GFP_VMALLOC32, NUMA_NO_NODE,
+                       __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vmalloc_32);
 
@@ -3054,6 +3001,7 @@ finished:
  * @vma:               vma to cover
  * @uaddr:             target user address to start at
  * @kaddr:             virtual address of vmalloc kernel memory
+ * @pgoff:             offset from @kaddr to start at
  * @size:              size of map area
  *
  * Returns:    0 for success, -Exxx on failure
@@ -3066,9 +3014,15 @@ finished:
  * Similar to remap_pfn_range() (see mm/memory.c)
  */
 int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
-                               void *kaddr, unsigned long size)
+                               void *kaddr, unsigned long pgoff,
+                               unsigned long size)
 {
        struct vm_struct *area;
+       unsigned long off;
+       unsigned long end_index;
+
+       if (check_shl_overflow(pgoff, PAGE_SHIFT, &off))
+               return -EINVAL;
 
        size = PAGE_ALIGN(size);
 
@@ -3082,8 +3036,10 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
        if (!(area->flags & (VM_USERMAP | VM_DMA_COHERENT)))
                return -EINVAL;
 
-       if (kaddr + size > area->addr + get_vm_area_size(area))
+       if (check_add_overflow(size, off, &end_index) ||
+           end_index > get_vm_area_size(area))
                return -EINVAL;
+       kaddr += off;
 
        do {
                struct page *page = vmalloc_to_page(kaddr);
@@ -3122,26 +3078,11 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
                                                unsigned long pgoff)
 {
        return remap_vmalloc_range_partial(vma, vma->vm_start,
-                                          addr + (pgoff << PAGE_SHIFT),
+                                          addr, pgoff,
                                           vma->vm_end - vma->vm_start);
 }
 EXPORT_SYMBOL(remap_vmalloc_range);
 
-/*
- * Implement stubs for vmalloc_sync_[un]mappings () if the architecture chose
- * not to have one.
- *
- * The purpose of this function is to make sure the vmalloc area
- * mappings are identical in all page-tables in the system.
- */
-void __weak vmalloc_sync_mappings(void)
-{
-}
-
-void __weak vmalloc_sync_unmappings(void)
-{
-}
-
 static int f(pte_t *pte, unsigned long addr, void *data)
 {
        pte_t ***p = data;
@@ -3368,7 +3309,7 @@ retry:
                        goto overflow;
 
                /*
-                * If required width exeeds current VA block, move
+                * If required width exceeds current VA block, move
                 * base downwards and then recheck.
                 */
                if (base + end > va->va_end) {