Skip to content

Commit 3ed3a4f

Browse files
kiryltorvalds
authored andcommitted
mm: cleanup *pte_alloc* interfaces
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(). [[email protected]: fix build for arm64 hugetlbpage] [[email protected]: fix arch/arm/mm/mmu.c some more] Signed-off-by: Kirill A. Shutemov <[email protected]> Cc: Dave Hansen <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Stephen Rothwell <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5057dcd commit 3ed3a4f

File tree

16 files changed

+27
-32
lines changed

16 files changed

+27
-32
lines changed

arch/arm/mm/mmu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static void *__init late_alloc(unsigned long sz)
732732
return ptr;
733733
}
734734

735-
static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr,
735+
static pte_t * __init arm_pte_alloc(pmd_t *pmd, unsigned long addr,
736736
unsigned long prot,
737737
void *(*alloc)(unsigned long sz))
738738
{
@@ -747,7 +747,7 @@ static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr,
747747
static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr,
748748
unsigned long prot)
749749
{
750-
return pte_alloc(pmd, addr, prot, early_alloc);
750+
return arm_pte_alloc(pmd, addr, prot, early_alloc);
751751
}
752752

753753
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,
756756
void *(*alloc)(unsigned long sz),
757757
bool ng)
758758
{
759-
pte_t *pte = pte_alloc(pmd, addr, type->prot_l1, alloc);
759+
pte_t *pte = arm_pte_alloc(pmd, addr, type->prot_l1, alloc);
760760
do {
761761
set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)),
762762
ng ? PTE_EXT_NG : 0);

arch/arm/mm/pgd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
8080
if (!new_pmd)
8181
goto no_pmd;
8282

83-
new_pte = pte_alloc_map(mm, NULL, new_pmd, 0);
83+
new_pte = pte_alloc_map(mm, new_pmd, 0);
8484
if (!new_pte)
8585
goto no_pte;
8686

arch/arm64/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
124124
* will be no pte_unmap() to correspond with this
125125
* pte_alloc_map().
126126
*/
127-
pte = pte_alloc_map(mm, NULL, pmd, addr);
127+
pte = pte_alloc_map(mm, pmd, addr);
128128
} else if (sz == PMD_SIZE) {
129129
if (IS_ENABLED(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) &&
130130
pud_none(*pud))

arch/ia64/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz)
3838
if (pud) {
3939
pmd = pmd_alloc(mm, pud, taddr);
4040
if (pmd)
41-
pte = pte_alloc_map(mm, NULL, pmd, taddr);
41+
pte = pte_alloc_map(mm, pmd, taddr);
4242
}
4343
return pte;
4444
}

arch/metag/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
6767
pgd = pgd_offset(mm, addr);
6868
pud = pud_offset(pgd, addr);
6969
pmd = pmd_offset(pud, addr);
70-
pte = pte_alloc_map(mm, NULL, pmd, addr);
70+
pte = pte_alloc_map(mm, pmd, addr);
7171
pgd->pgd &= ~_PAGE_SZ_MASK;
7272
pgd->pgd |= _PAGE_SZHUGE;
7373

arch/parisc/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
6363
if (pud) {
6464
pmd = pmd_alloc(mm, pud, addr);
6565
if (pmd)
66-
pte = pte_alloc_map(mm, NULL, pmd, addr);
66+
pte = pte_alloc_map(mm, pmd, addr);
6767
}
6868
return pte;
6969
}

arch/sh/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
3535
if (pud) {
3636
pmd = pmd_alloc(mm, pud, addr);
3737
if (pmd)
38-
pte = pte_alloc_map(mm, NULL, pmd, addr);
38+
pte = pte_alloc_map(mm, pmd, addr);
3939
}
4040
}
4141

arch/sparc/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
146146
if (pud) {
147147
pmd = pmd_alloc(mm, pud, addr);
148148
if (pmd)
149-
pte = pte_alloc_map(mm, NULL, pmd, addr);
149+
pte = pte_alloc_map(mm, pmd, addr);
150150
}
151151
return pte;
152152
}

arch/tile/mm/hugetlbpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
7777
else {
7878
if (sz != PAGE_SIZE << huge_shift[HUGE_SHIFT_PAGE])
7979
panic("Unexpected page size %#lx\n", sz);
80-
return pte_alloc_map(mm, NULL, pmd, addr);
80+
return pte_alloc_map(mm, pmd, addr);
8181
}
8282
}
8383
#else

arch/um/kernel/skas/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
3131
if (!pmd)
3232
goto out_pmd;
3333

34-
pte = pte_alloc_map(mm, NULL, pmd, proc);
34+
pte = pte_alloc_map(mm, pmd, proc);
3535
if (!pte)
3636
goto out_pte;
3737

arch/unicore32/mm/pgd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
5454
if (!new_pmd)
5555
goto no_pmd;
5656

57-
new_pte = pte_alloc_map(mm, NULL, new_pmd, 0);
57+
new_pte = pte_alloc_map(mm, new_pmd, 0);
5858
if (!new_pte)
5959
goto no_pte;
6060

arch/x86/kernel/tboot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int map_tboot_page(unsigned long vaddr, unsigned long pfn,
135135
pmd = pmd_alloc(&tboot_mm, pud, vaddr);
136136
if (!pmd)
137137
return -1;
138-
pte = pte_alloc_map(&tboot_mm, NULL, pmd, vaddr);
138+
pte = pte_alloc_map(&tboot_mm, pmd, vaddr);
139139
if (!pte)
140140
return -1;
141141
set_pte_at(&tboot_mm, vaddr, pte, pfn_pte(pfn, prot));

include/linux/mm.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,7 @@ static inline void mm_dec_nr_pmds(struct mm_struct *mm)
15451545
}
15461546
#endif
15471547

1548-
int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
1549-
pmd_t *pmd, unsigned long address);
1548+
int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address);
15501549
int __pte_alloc_kernel(pmd_t *pmd, unsigned long address);
15511550

15521551
/*
@@ -1672,15 +1671,15 @@ static inline void pgtable_page_dtor(struct page *page)
16721671
pte_unmap(pte); \
16731672
} while (0)
16741673

1675-
#define pte_alloc_map(mm, vma, pmd, address) \
1676-
((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, vma, \
1677-
pmd, address))? \
1678-
NULL: pte_offset_map(pmd, address))
1674+
#define pte_alloc(mm, pmd, address) \
1675+
(unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, pmd, address))
1676+
1677+
#define pte_alloc_map(mm, pmd, address) \
1678+
(pte_alloc(mm, pmd, address) ? NULL : pte_offset_map(pmd, address))
16791679

16801680
#define pte_alloc_map_lock(mm, pmd, address, ptlp) \
1681-
((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, NULL, \
1682-
pmd, address))? \
1683-
NULL: pte_offset_map_lock(mm, pmd, address, ptlp))
1681+
(pte_alloc(mm, pmd, address) ? \
1682+
NULL : pte_offset_map_lock(mm, pmd, address, ptlp))
16841683

16851684
#define pte_alloc_kernel(pmd, address) \
16861685
((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel(pmd, address))? \

mm/memory.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma,
562562
}
563563
}
564564

565-
int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
566-
pmd_t *pmd, unsigned long address)
565+
int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
567566
{
568567
spinlock_t *ptl;
569568
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,
34193418
}
34203419

34213420
/*
3422-
* Use __pte_alloc instead of pte_alloc_map, because we can't
3421+
* Use pte_alloc() instead of pte_alloc_map, because we can't
34233422
* run pte_offset_map on the pmd, if an huge pmd could
34243423
* materialize from under us from a different thread.
34253424
*/
3426-
if (unlikely(pmd_none(*pmd)) &&
3427-
unlikely(__pte_alloc(mm, vma, pmd, address)))
3425+
if (unlikely(pte_alloc(mm, pmd, address)))
34283426
return VM_FAULT_OOM;
34293427
/*
34303428
* If a huge pmd materialized under us just retry later. Use

mm/mremap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
213213
continue;
214214
VM_BUG_ON(pmd_trans_huge(*old_pmd));
215215
}
216-
if (pmd_none(*new_pmd) && __pte_alloc(new_vma->vm_mm, new_vma,
217-
new_pmd, new_addr))
216+
if (pte_alloc(new_vma->vm_mm, new_pmd, new_addr))
218217
break;
219218
next = (new_addr + PMD_SIZE) & PMD_MASK;
220219
if (extent > next - new_addr)

mm/userfaultfd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm,
230230
break;
231231
}
232232
if (unlikely(pmd_none(dst_pmdval)) &&
233-
unlikely(__pte_alloc(dst_mm, dst_vma, dst_pmd,
234-
dst_addr))) {
233+
unlikely(__pte_alloc(dst_mm, dst_pmd, dst_addr))) {
235234
err = -ENOMEM;
236235
break;
237236
}

0 commit comments

Comments
 (0)