mm: cleanup *pte_alloc* interfaces
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Thu, 17 Mar 2016 21:19:11 +0000 (14:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Mar 2016 22:09:34 +0000 (15:09 -0700)
There are few things about *pte_alloc*() helpers worth cleaning up:

 - 'vma' argument is unused, let's drop it;

 - most __pte_alloc() callers do speculative check for pmd_none(),
   before taking ptl: let's introduce pte_alloc() macro which does
   the check.

   The only direct user of __pte_alloc left is userfaultfd, which has
   different expectation about atomicity wrt pmd.

 - pte_alloc_map() and pte_alloc_map_lock() are redefined using
   pte_alloc().

[sudeep.holla@arm.com: fix build for arm64 hugetlbpage]
[sfr@canb.auug.org.au: fix arch/arm/mm/mmu.c some more]
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
16 files changed:
arch/arm/mm/mmu.c
arch/arm/mm/pgd.c
arch/arm64/mm/hugetlbpage.c
arch/ia64/mm/hugetlbpage.c
arch/metag/mm/hugetlbpage.c
arch/parisc/mm/hugetlbpage.c
arch/sh/mm/hugetlbpage.c
arch/sparc/mm/hugetlbpage.c
arch/tile/mm/hugetlbpage.c
arch/um/kernel/skas/mmu.c
arch/unicore32/mm/pgd.c
arch/x86/kernel/tboot.c
include/linux/mm.h
mm/memory.c
mm/mremap.c
mm/userfaultfd.c

index 434d76f0b36314e3731fe74376b7db5bc92483a6..88fbe0d23ca613a77b68f7da292f0b5864238647 100644 (file)
@@ -732,7 +732,7 @@ static void *__init late_alloc(unsigned long sz)
        return ptr;
 }
 
-static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr,
+static pte_t * __init arm_pte_alloc(pmd_t *pmd, unsigned long addr,
                                unsigned long prot,
                                void *(*alloc)(unsigned long sz))
 {
@@ -747,7 +747,7 @@ static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr,
 static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr,
                                      unsigned long prot)
 {
-       return pte_alloc(pmd, addr, prot, early_alloc);
+       return arm_pte_alloc(pmd, addr, prot, early_alloc);
 }
 
 static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
@@ -756,7 +756,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
                                  void *(*alloc)(unsigned long sz),
                                  bool ng)
 {
-       pte_t *pte = pte_alloc(pmd, addr, type->prot_l1, alloc);
+       pte_t *pte = arm_pte_alloc(pmd, addr, type->prot_l1, alloc);
        do {
                set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)),
                            ng ? PTE_EXT_NG : 0);
index e683db1b90a3f805d1de8f92a9c0ebe544960368..b8d477321730ede65f9fdd847c164862db7bbc45 100644 (file)
@@ -80,7 +80,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
                if (!new_pmd)
                        goto no_pmd;
 
-               new_pte = pte_alloc_map(mm, NULL, new_pmd, 0);
+               new_pte = pte_alloc_map(mm, new_pmd, 0);
                if (!new_pte)
                        goto no_pte;
 
index da30529bb1f65c9e3d5408b2e28ab31bc2283211..589fd28e1fb5de8b923fc99ee0fa35d79b1cd6af 100644 (file)
@@ -124,7 +124,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
                 * will be no pte_unmap() to correspond with this
                 * pte_alloc_map().
                 */
-               pte = pte_alloc_map(mm, NULL, pmd, addr);
+               pte = pte_alloc_map(mm, pmd, addr);
        } else if (sz == PMD_SIZE) {
                if (IS_ENABLED(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) &&
                    pud_none(*pud))
index f50d4b3f501ad6a5cd0fcf10dfd66b82500b0e54..85de86d36fdf2a71783697212e2e5cdb1e2dbc46 100644 (file)
@@ -38,7 +38,7 @@ huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz)
        if (pud) {
                pmd = pmd_alloc(mm, pud, taddr);
                if (pmd)
-                       pte = pte_alloc_map(mm, NULL, pmd, taddr);
+                       pte = pte_alloc_map(mm, pmd, taddr);
        }
        return pte;
 }
index 53f0f6c470273b9c7c48ad6976b3e526a929ed52..b38700ae4e8429cdd6b56226ed82d523f4153d44 100644 (file)
@@ -67,7 +67,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
        pgd = pgd_offset(mm, addr);
        pud = pud_offset(pgd, addr);
        pmd = pmd_offset(pud, addr);
-       pte = pte_alloc_map(mm, NULL, pmd, addr);
+       pte = pte_alloc_map(mm, pmd, addr);
        pgd->pgd &= ~_PAGE_SZ_MASK;
        pgd->pgd |= _PAGE_SZHUGE;
 
index 54ba39262b8239aba1d8e4adc267d211b9d72275..5d6eea925cf4ec979e906b118a682f318a199f01 100644 (file)
@@ -63,7 +63,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
        if (pud) {
                pmd = pmd_alloc(mm, pud, addr);
                if (pmd)
-                       pte = pte_alloc_map(mm, NULL, pmd, addr);
+                       pte = pte_alloc_map(mm, pmd, addr);
        }
        return pte;
 }
index 6385f60209b65adefc2bbbcc8e5309a5d574455d..cc948db74878045bdcfeeed4c17d821098f0c3fa 100644 (file)
@@ -35,7 +35,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
                if (pud) {
                        pmd = pmd_alloc(mm, pud, addr);
                        if (pmd)
-                               pte = pte_alloc_map(mm, NULL, pmd, addr);
+                               pte = pte_alloc_map(mm, pmd, addr);
                }
        }
 
index 131eaf4ad7f598aacaaf31a8f59da9ad1335c2da..4977800e9770552e44b9fd4571d6aa90e15168ed 100644 (file)
@@ -146,7 +146,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
        if (pud) {
                pmd = pmd_alloc(mm, pud, addr);
                if (pmd)
-                       pte = pte_alloc_map(mm, NULL, pmd, addr);
+                       pte = pte_alloc_map(mm, pmd, addr);
        }
        return pte;
 }
index c034dc3fe2d42cb80502517816dd188ff8801557..e212c64682c55bcaaa9b4aa78c13cf6326a95e39 100644 (file)
@@ -77,7 +77,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
                else {
                        if (sz != PAGE_SIZE << huge_shift[HUGE_SHIFT_PAGE])
                                panic("Unexpected page size %#lx\n", sz);
-                       return pte_alloc_map(mm, NULL, pmd, addr);
+                       return pte_alloc_map(mm, pmd, addr);
                }
        }
 #else
index 9591a66aa5c513b5fe8773e2b21634c19b3758ed..3943e9d7d13d2d28f1b83b1fc8da5500acef795d 100644 (file)
@@ -31,7 +31,7 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
        if (!pmd)
                goto out_pmd;
 
-       pte = pte_alloc_map(mm, NULL, pmd, proc);
+       pte = pte_alloc_map(mm, pmd, proc);
        if (!pte)
                goto out_pte;
 
index 2ade20d8eab3965d749e2c44d475cc931b52a3c3..c572a28c76c98997f5a4a80af3dc63d3119abc0f 100644 (file)
@@ -54,7 +54,7 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
                if (!new_pmd)
                        goto no_pmd;
 
-               new_pte = pte_alloc_map(mm, NULL, new_pmd, 0);
+               new_pte = pte_alloc_map(mm, new_pmd, 0);
                if (!new_pte)
                        goto no_pte;
 
index 91a4496db43429de294e481075782295b76ff0e6..e72a07f20b05cfb079f2dca79e063b1dd340f2e4 100644 (file)
@@ -135,7 +135,7 @@ static int map_tboot_page(unsigned long vaddr, unsigned long pfn,
        pmd = pmd_alloc(&tboot_mm, pud, vaddr);
        if (!pmd)
                return -1;
-       pte = pte_alloc_map(&tboot_mm, NULL, pmd, vaddr);
+       pte = pte_alloc_map(&tboot_mm, pmd, vaddr);
        if (!pte)
                return -1;
        set_pte_at(&tboot_mm, vaddr, pte, pfn_pte(pfn, prot));
index db9df3f78de11d7ad8d9049c2383c07eee44fd00..75d1907b9009b153d6218ea48d877bf514c6a31d 100644 (file)
@@ -1545,8 +1545,7 @@ static inline void mm_dec_nr_pmds(struct mm_struct *mm)
 }
 #endif
 
-int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
-               pmd_t *pmd, unsigned long address);
+int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address);
 int __pte_alloc_kernel(pmd_t *pmd, unsigned long address);
 
 /*
@@ -1672,15 +1671,15 @@ static inline void pgtable_page_dtor(struct page *page)
        pte_unmap(pte);                                 \
 } while (0)
 
-#define pte_alloc_map(mm, vma, pmd, address)                           \
-       ((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, vma,    \
-                                                       pmd, address))? \
-        NULL: pte_offset_map(pmd, address))
+#define pte_alloc(mm, pmd, address)                    \
+       (unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, pmd, address))
+
+#define pte_alloc_map(mm, pmd, address)                        \
+       (pte_alloc(mm, pmd, address) ? NULL : pte_offset_map(pmd, address))
 
 #define pte_alloc_map_lock(mm, pmd, address, ptlp)     \
-       ((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, NULL,   \
-                                                       pmd, address))? \
-               NULL: pte_offset_map_lock(mm, pmd, address, ptlp))
+       (pte_alloc(mm, pmd, address) ?                  \
+                NULL : pte_offset_map_lock(mm, pmd, address, ptlp))
 
 #define pte_alloc_kernel(pmd, address)                 \
        ((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel(pmd, address))? \
index 0e247642ed5b7567ebbf97259df003580bfffb4d..1974fc02c4d0e68244b342438538e9b580e2a6eb 100644 (file)
@@ -562,8 +562,7 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma,
        }
 }
 
-int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
-               pmd_t *pmd, unsigned long address)
+int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
 {
        spinlock_t *ptl;
        pgtable_t new = pte_alloc_one(mm, address);
@@ -3419,12 +3418,11 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        }
 
        /*
-        * Use __pte_alloc instead of pte_alloc_map, because we can't
+        * Use pte_alloc() instead of pte_alloc_map, because we can't
         * run pte_offset_map on the pmd, if an huge pmd could
         * materialize from under us from a different thread.
         */
-       if (unlikely(pmd_none(*pmd)) &&
-           unlikely(__pte_alloc(mm, vma, pmd, address)))
+       if (unlikely(pte_alloc(mm, pmd, address)))
                return VM_FAULT_OOM;
        /*
         * If a huge pmd materialized under us just retry later.  Use
index e30c8a6489a6e607548eb96c57db8d0c0cd461b1..3fa0a467df66749e5021e29cb504a1924526bcad 100644 (file)
@@ -213,8 +213,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
                                continue;
                        VM_BUG_ON(pmd_trans_huge(*old_pmd));
                }
-               if (pmd_none(*new_pmd) && __pte_alloc(new_vma->vm_mm, new_vma,
-                                                     new_pmd, new_addr))
+               if (pte_alloc(new_vma->vm_mm, new_pmd, new_addr))
                        break;
                next = (new_addr + PMD_SIZE) & PMD_MASK;
                if (extent > next - new_addr)
index 806b0c758c5b6113de9b921ff0cfd01fd45b6424..9f3a0290b2739665c22ab58087d1737aea91ca59 100644 (file)
@@ -230,8 +230,7 @@ retry:
                        break;
                }
                if (unlikely(pmd_none(dst_pmdval)) &&
-                   unlikely(__pte_alloc(dst_mm, dst_vma, dst_pmd,
-                                        dst_addr))) {
+                   unlikely(__pte_alloc(dst_mm, dst_pmd, dst_addr))) {
                        err = -ENOMEM;
                        break;
                }