This source file includes following definitions.
- __hash_page_thp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <linux/mm.h>
19 #include <asm/machdep.h>
20
21 int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
22 pmd_t *pmdp, unsigned long trap, unsigned long flags,
23 int ssize, unsigned int psize)
24 {
25 unsigned int index, valid;
26 unsigned char *hpte_slot_array;
27 unsigned long rflags, pa, hidx;
28 unsigned long old_pmd, new_pmd;
29 int ret, lpsize = MMU_PAGE_16M;
30 unsigned long vpn, hash, shift, slot;
31
32
33
34
35 do {
36 pmd_t pmd = READ_ONCE(*pmdp);
37
38 old_pmd = pmd_val(pmd);
39
40 if (unlikely(old_pmd & H_PAGE_BUSY))
41 return 0;
42
43 if (unlikely(!check_pte_access(access, old_pmd)))
44 return 1;
45
46
47
48
49 new_pmd = old_pmd | H_PAGE_BUSY | _PAGE_ACCESSED;
50 if (access & _PAGE_WRITE)
51 new_pmd |= _PAGE_DIRTY;
52 } while (!pmd_xchg(pmdp, __pmd(old_pmd), __pmd(new_pmd)));
53
54
55
56
57 if (!(old_pmd & (H_PAGE_THP_HUGE | _PAGE_DEVMAP)))
58 return 0;
59
60 rflags = htab_convert_pte_flags(new_pmd);
61
62 #if 0
63 if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
64
65
66
67
68
69 rflags = hash_page_do_lazy_icache(rflags, __pte(old_pte), trap);
70 }
71 #endif
72
73
74
75 shift = mmu_psize_defs[psize].shift;
76 index = (ea & ~HPAGE_PMD_MASK) >> shift;
77 BUG_ON(index >= PTE_FRAG_SIZE);
78
79 vpn = hpt_vpn(ea, vsid, ssize);
80 hpte_slot_array = get_hpte_slot_array(pmdp);
81 if (psize == MMU_PAGE_4K) {
82
83
84
85
86
87 if ((old_pmd & H_PAGE_HASHPTE) && !(old_pmd & H_PAGE_COMBO)) {
88 flush_hash_hugepage(vsid, ea, pmdp, MMU_PAGE_64K,
89 ssize, flags);
90
91
92
93
94
95
96
97
98 memset(hpte_slot_array, 0, PTE_FRAG_SIZE);
99 }
100 }
101
102 valid = hpte_valid(hpte_slot_array, index);
103 if (valid) {
104
105 hash = hpt_hash(vpn, shift, ssize);
106 hidx = hpte_hash_index(hpte_slot_array, index);
107 if (hidx & _PTEIDX_SECONDARY)
108 hash = ~hash;
109 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
110 slot += hidx & _PTEIDX_GROUP_IX;
111
112 ret = mmu_hash_ops.hpte_updatepp(slot, rflags, vpn,
113 psize, lpsize, ssize, flags);
114
115
116
117 if (ret == -1) {
118
119
120
121
122
123 valid = 0;
124 hpte_slot_array[index] = 0;
125 }
126 }
127
128 if (!valid) {
129 unsigned long hpte_group;
130
131 hash = hpt_hash(vpn, shift, ssize);
132
133 pa = pmd_pfn(__pmd(old_pmd)) << PAGE_SHIFT;
134 new_pmd |= H_PAGE_HASHPTE;
135
136 repeat:
137 hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP;
138
139
140 slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, 0,
141 psize, lpsize, ssize);
142
143
144
145 if (unlikely(slot == -1)) {
146 hpte_group = (~hash & htab_hash_mask) * HPTES_PER_GROUP;
147 slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa,
148 rflags,
149 HPTE_V_SECONDARY,
150 psize, lpsize, ssize);
151 if (slot == -1) {
152 if (mftb() & 0x1)
153 hpte_group = (hash & htab_hash_mask) *
154 HPTES_PER_GROUP;
155
156 mmu_hash_ops.hpte_remove(hpte_group);
157 goto repeat;
158 }
159 }
160
161
162
163
164 if (unlikely(slot == -2)) {
165 *pmdp = __pmd(old_pmd);
166 hash_failure_debug(ea, access, vsid, trap, ssize,
167 psize, lpsize, old_pmd);
168 return -1;
169 }
170
171
172
173
174
175 mark_hpte_slot_valid(hpte_slot_array, index, slot);
176 }
177
178
179
180
181 if (psize == MMU_PAGE_4K)
182 new_pmd |= H_PAGE_COMBO;
183
184
185
186
187
188 smp_wmb();
189 *pmdp = __pmd(new_pmd & ~H_PAGE_BUSY);
190 return 0;
191 }