Blame view
mm/pgtable-generic.c
5.59 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
e2cda3226 thp: add pmd mang... |
2 3 4 |
/* * mm/pgtable-generic.c * |
ca5999fde mm: introduce inc... |
5 |
* Generic pgtable methods declared in linux/pgtable.h |
e2cda3226 thp: add pmd mang... |
6 7 8 |
* * Copyright (C) 2010 Linus Torvalds */ |
f95ba941d mm/pgtable-generi... |
9 |
#include <linux/pagemap.h> |
a31acd3ee x86/mm: Page size... |
10 |
#include <linux/hugetlb.h> |
ca5999fde mm: introduce inc... |
11 |
#include <linux/pgtable.h> |
e2cda3226 thp: add pmd mang... |
12 |
#include <asm/tlb.h> |
e2cda3226 thp: add pmd mang... |
13 |
|
bc4b4448d mm: move pgtable ... |
14 15 16 17 18 19 20 21 22 23 24 |
/* * If a p?d_bad entry is found while walking page tables, report * the error, before resetting entry to p?d_none. Usually (but * very seldom) called out from the p?d_none_or_clear_bad macros. */ void pgd_clear_bad(pgd_t *pgd) { pgd_ERROR(*pgd); pgd_clear(pgd); } |
f2400abc7 asm-generic/mm: s... |
25 |
#ifndef __PAGETABLE_P4D_FOLDED |
c2febafc6 mm: convert gener... |
26 27 28 29 30 |
void p4d_clear_bad(p4d_t *p4d) { p4d_ERROR(*p4d); p4d_clear(p4d); } |
f2400abc7 asm-generic/mm: s... |
31 |
#endif |
c2febafc6 mm: convert gener... |
32 |
|
f2400abc7 asm-generic/mm: s... |
33 |
#ifndef __PAGETABLE_PUD_FOLDED |
bc4b4448d mm: move pgtable ... |
34 35 36 37 38 |
void pud_clear_bad(pud_t *pud) { pud_ERROR(*pud); pud_clear(pud); } |
f2400abc7 asm-generic/mm: s... |
39 |
#endif |
bc4b4448d mm: move pgtable ... |
40 |
|
f2400abc7 asm-generic/mm: s... |
41 42 43 44 45 |
/* * Note that the pmd variant below can't be stub'ed out just as for p4d/pud * above. pmd folding is special and typically pmd_* macros refer to upper * level even when folded */ |
bc4b4448d mm: move pgtable ... |
46 47 48 49 50 |
void pmd_clear_bad(pmd_t *pmd) { pmd_ERROR(*pmd); pmd_clear(pmd); } |
e2cda3226 thp: add pmd mang... |
51 52 |
#ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS /* |
ca5999fde mm: introduce inc... |
53 |
* Only sets the access flags (dirty, accessed), as well as write |
cef23d9db mm,generic: only ... |
54 |
* permission. Furthermore, we know it always gets set to a "more |
e2cda3226 thp: add pmd mang... |
55 56 57 58 59 60 61 62 63 64 65 66 67 |
* permissive" setting, which allows most architectures to optimize * this. We return whether the PTE actually changed, which in turn * instructs the caller to do things like update__mmu_cache. This * used to be done in the caller, but sparc needs minor faults to * force that call on sun4c so we changed this macro slightly */ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t entry, int dirty) { int changed = !pte_same(*ptep, entry); if (changed) { set_pte_at(vma->vm_mm, address, ptep, entry); |
cef23d9db mm,generic: only ... |
68 |
flush_tlb_fix_spurious_fault(vma, address); |
e2cda3226 thp: add pmd mang... |
69 70 71 72 |
} return changed; } #endif |
52585bcc2 mm: group pte rel... |
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
#ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { int young; young = ptep_test_and_clear_young(vma, address, ptep); if (young) flush_tlb_page(vma, address); return young; } #endif #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { struct mm_struct *mm = (vma)->vm_mm; pte_t pte; pte = ptep_get_and_clear(mm, address, ptep); if (pte_accessible(mm, pte)) flush_tlb_page(vma, address); return pte; } #endif |
bd5e88ad7 mm,thp: reduce if... |
97 |
#ifdef CONFIG_TRANSPARENT_HUGEPAGE |
e2cda3226 thp: add pmd mang... |
98 99 100 101 102 |
#ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp, pmd_t entry, int dirty) { |
e2cda3226 thp: add pmd mang... |
103 104 105 106 |
int changed = !pmd_same(*pmdp, entry); VM_BUG_ON(address & ~HPAGE_PMD_MASK); if (changed) { set_pmd_at(vma->vm_mm, address, pmdp, entry); |
12ebc1581 mm,thp: introduce... |
107 |
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE); |
e2cda3226 thp: add pmd mang... |
108 109 |
} return changed; |
e2cda3226 thp: add pmd mang... |
110 111 |
} #endif |
e2cda3226 thp: add pmd mang... |
112 113 114 115 116 |
#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH int pmdp_clear_flush_young(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp) { int young; |
d8c37c480 thp: add HPAGE_PM... |
117 |
VM_BUG_ON(address & ~HPAGE_PMD_MASK); |
e2cda3226 thp: add pmd mang... |
118 119 |
young = pmdp_test_and_clear_young(vma, address, pmdp); if (young) |
12ebc1581 mm,thp: introduce... |
120 |
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE); |
e2cda3226 thp: add pmd mang... |
121 122 123 |
return young; } #endif |
8809aa2d2 mm: clarify that ... |
124 |
#ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH |
8809aa2d2 mm: clarify that ... |
125 126 |
pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp) |
e2cda3226 thp: add pmd mang... |
127 128 |
{ pmd_t pmd; |
e2cda3226 thp: add pmd mang... |
129 |
VM_BUG_ON(address & ~HPAGE_PMD_MASK); |
616b83715 mm: thp: enable t... |
130 131 |
VM_BUG_ON((pmd_present(*pmdp) && !pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp)) || !pmd_present(*pmdp)); |
8809aa2d2 mm: clarify that ... |
132 |
pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp); |
12ebc1581 mm,thp: introduce... |
133 |
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE); |
e2cda3226 thp: add pmd mang... |
134 135 |
return pmd; } |
a00cc7d9d mm, x86: add supp... |
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD pud_t pudp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address, pud_t *pudp) { pud_t pud; VM_BUG_ON(address & ~HPAGE_PUD_MASK); VM_BUG_ON(!pud_trans_huge(*pudp) && !pud_devmap(*pudp)); pud = pudp_huge_get_and_clear(vma->vm_mm, address, pudp); flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE); return pud; } #endif |
e2cda3226 thp: add pmd mang... |
150 |
#endif |
e3ebcf643 thp: remove assum... |
151 |
#ifndef __HAVE_ARCH_PGTABLE_DEPOSIT |
6b0b50b06 mm/THP: add pmd a... |
152 153 |
void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, pgtable_t pgtable) |
e3ebcf643 thp: remove assum... |
154 |
{ |
c4088ebdc mm: convert the r... |
155 |
assert_spin_locked(pmd_lockptr(mm, pmdp)); |
e3ebcf643 thp: remove assum... |
156 157 |
/* FIFO */ |
c389a250a mm, thp: do not a... |
158 |
if (!pmd_huge_pte(mm, pmdp)) |
e3ebcf643 thp: remove assum... |
159 160 |
INIT_LIST_HEAD(&pgtable->lru); else |
c389a250a mm, thp: do not a... |
161 162 |
list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru); pmd_huge_pte(mm, pmdp) = pgtable; |
e3ebcf643 thp: remove assum... |
163 |
} |
e3ebcf643 thp: remove assum... |
164 165 166 |
#endif #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW |
e3ebcf643 thp: remove assum... |
167 |
/* no "address" argument so destroys page coloring of some arch */ |
6b0b50b06 mm/THP: add pmd a... |
168 |
pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp) |
e3ebcf643 thp: remove assum... |
169 170 |
{ pgtable_t pgtable; |
c4088ebdc mm: convert the r... |
171 |
assert_spin_locked(pmd_lockptr(mm, pmdp)); |
e3ebcf643 thp: remove assum... |
172 173 |
/* FIFO */ |
c389a250a mm, thp: do not a... |
174 |
pgtable = pmd_huge_pte(mm, pmdp); |
146693471 mm, thp: use list... |
175 176 177 |
pmd_huge_pte(mm, pmdp) = list_first_entry_or_null(&pgtable->lru, struct page, lru); if (pmd_huge_pte(mm, pmdp)) |
e3ebcf643 thp: remove assum... |
178 |
list_del(&pgtable->lru); |
e3ebcf643 thp: remove assum... |
179 180 |
return pgtable; } |
e3ebcf643 thp: remove assum... |
181 |
#endif |
46dcde735 thp: introduce pm... |
182 183 |
#ifndef __HAVE_ARCH_PMDP_INVALIDATE |
d52605d7c mm: do not lose d... |
184 |
pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, |
46dcde735 thp: introduce pm... |
185 186 |
pmd_t *pmdp) { |
86ec2da03 mm/thp: rename pm... |
187 |
pmd_t old = pmdp_establish(vma, address, pmdp, pmd_mkinvalid(*pmdp)); |
12ebc1581 mm,thp: introduce... |
188 |
flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE); |
d52605d7c mm: do not lose d... |
189 |
return old; |
46dcde735 thp: introduce pm... |
190 |
} |
46dcde735 thp: introduce pm... |
191 |
#endif |
f28b6ff8c powerpc/mm: use g... |
192 193 |
#ifndef pmdp_collapse_flush |
f28b6ff8c powerpc/mm: use g... |
194 195 196 |
pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp) { |
8809aa2d2 mm: clarify that ... |
197 198 199 200 |
/* * pmd and hugepage pte format are same. So we could * use the same function. */ |
f28b6ff8c powerpc/mm: use g... |
201 202 203 204 |
pmd_t pmd; VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(pmd_trans_huge(*pmdp)); |
8809aa2d2 mm: clarify that ... |
205 |
pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp); |
6a6ac72fd mm,thp: khugepage... |
206 207 208 |
/* collapse entails shooting down ptes not pmd */ flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE); |
f28b6ff8c powerpc/mm: use g... |
209 210 |
return pmd; } |
f28b6ff8c powerpc/mm: use g... |
211 |
#endif |
bd5e88ad7 mm,thp: reduce if... |
212 |
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |