Lines Matching +full:mm +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2007-2008 Paul Mackerras, IBM Corp.
22 void subpage_prot_free(struct mm_struct *mm) in subpage_prot_free() argument
24 struct subpage_prot_table *spt = mm_ctx_subpage_prot(&mm->context); in subpage_prot_free()
31 for (i = 0; i < 4; ++i) { in subpage_prot_free()
32 if (spt->low_prot[i]) { in subpage_prot_free()
33 free_page((unsigned long)spt->low_prot[i]); in subpage_prot_free()
34 spt->low_prot[i] = NULL; in subpage_prot_free()
37 addr = 0; in subpage_prot_free()
38 for (i = 0; i < (TASK_SIZE_USER64 >> 43); ++i) { in subpage_prot_free()
39 p = spt->protptrs[i]; in subpage_prot_free()
42 spt->protptrs[i] = NULL; in subpage_prot_free()
43 for (j = 0; j < SBP_L2_COUNT && addr < spt->maxaddr; in subpage_prot_free()
49 spt->maxaddr = 0; in subpage_prot_free()
53 static void hpte_flush_range(struct mm_struct *mm, unsigned long addr, in hpte_flush_range() argument
63 pgd = pgd_offset(mm, addr); in hpte_flush_range()
73 pte = pte_offset_map_lock(mm, pmd, addr, &ptl); in hpte_flush_range()
77 for (; npages > 0; --npages) { in hpte_flush_range()
78 pte_update(mm, addr, pte, 0, 0, 0); in hpte_flush_range()
83 pte_unmap_unlock(pte - 1, ptl); in hpte_flush_range()
92 struct mm_struct *mm = current->mm; in subpage_prot_clear() local
99 mmap_write_lock(mm); in subpage_prot_clear()
101 spt = mm_ctx_subpage_prot(&mm->context); in subpage_prot_clear()
106 if (limit > spt->maxaddr) in subpage_prot_clear()
107 limit = spt->maxaddr; in subpage_prot_clear()
110 if (addr < 0x100000000UL) { in subpage_prot_clear()
111 spm = spt->low_prot; in subpage_prot_clear()
113 spm = spt->protptrs[addr >> SBP_L3_SHIFT]; in subpage_prot_clear()
117 spp = spm[(addr >> SBP_L2_SHIFT) & (SBP_L2_COUNT - 1)]; in subpage_prot_clear()
120 spp += (addr >> PAGE_SHIFT) & (SBP_L1_COUNT - 1); in subpage_prot_clear()
122 i = (addr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1); in subpage_prot_clear()
123 nw = PTRS_PER_PTE - i; in subpage_prot_clear()
125 nw = (next - addr) >> PAGE_SHIFT; in subpage_prot_clear()
127 memset(spp, 0, nw * sizeof(u32)); in subpage_prot_clear()
130 hpte_flush_range(mm, addr, nw); in subpage_prot_clear()
134 mmap_write_unlock(mm); in subpage_prot_clear()
141 struct vm_area_struct *vma = walk->vma; in subpage_walk_pmd_entry()
143 return 0; in subpage_walk_pmd_entry()
151 static void subpage_mark_vma_nohuge(struct mm_struct *mm, unsigned long addr, in subpage_mark_vma_nohuge() argument
155 VMA_ITERATOR(vmi, mm, addr); in subpage_mark_vma_nohuge()
167 static void subpage_mark_vma_nohuge(struct mm_struct *mm, unsigned long addr, in subpage_mark_vma_nohuge() argument
177 * Each 2-bit field is 0 to allow any access, 1 to prevent writes,
180 * protection mechanism is an additional constraint, so putting 0
181 * in a 2-bit field won't allow writes to a page that is otherwise
182 * write-protected.
187 struct mm_struct *mm = current->mm; in SYSCALL_DEFINE3() local
196 return -ENOENT; in SYSCALL_DEFINE3()
200 addr >= mm->task_size || len >= mm->task_size || in SYSCALL_DEFINE3()
201 addr + len > mm->task_size) in SYSCALL_DEFINE3()
202 return -EINVAL; in SYSCALL_DEFINE3()
204 if (is_hugepage_only_range(mm, addr, len)) in SYSCALL_DEFINE3()
205 return -EINVAL; in SYSCALL_DEFINE3()
210 return 0; in SYSCALL_DEFINE3()
214 return -EFAULT; in SYSCALL_DEFINE3()
216 mmap_write_lock(mm); in SYSCALL_DEFINE3()
218 spt = mm_ctx_subpage_prot(&mm->context); in SYSCALL_DEFINE3()
226 err = -ENOMEM; in SYSCALL_DEFINE3()
229 mm->context.hash_context->spt = spt; in SYSCALL_DEFINE3()
232 subpage_mark_vma_nohuge(mm, addr, len); in SYSCALL_DEFINE3()
235 err = -ENOMEM; in SYSCALL_DEFINE3()
236 if (addr < 0x100000000UL) { in SYSCALL_DEFINE3()
237 spm = spt->low_prot; in SYSCALL_DEFINE3()
239 spm = spt->protptrs[addr >> SBP_L3_SHIFT]; in SYSCALL_DEFINE3()
244 spt->protptrs[addr >> SBP_L3_SHIFT] = spm; in SYSCALL_DEFINE3()
247 spm += (addr >> SBP_L2_SHIFT) & (SBP_L2_COUNT - 1); in SYSCALL_DEFINE3()
255 spp += (addr >> PAGE_SHIFT) & (SBP_L1_COUNT - 1); in SYSCALL_DEFINE3()
258 demote_segment_4k(mm, addr); in SYSCALL_DEFINE3()
261 i = (addr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1); in SYSCALL_DEFINE3()
262 nw = PTRS_PER_PTE - i; in SYSCALL_DEFINE3()
264 nw = (next - addr) >> PAGE_SHIFT; in SYSCALL_DEFINE3()
266 mmap_write_unlock(mm); in SYSCALL_DEFINE3()
268 return -EFAULT; in SYSCALL_DEFINE3()
270 mmap_write_lock(mm); in SYSCALL_DEFINE3()
273 hpte_flush_range(mm, addr, nw); in SYSCALL_DEFINE3()
275 if (limit > spt->maxaddr) in SYSCALL_DEFINE3()
276 spt->maxaddr = limit; in SYSCALL_DEFINE3()
277 err = 0; in SYSCALL_DEFINE3()
279 mmap_write_unlock(mm); in SYSCALL_DEFINE3()