Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 1 | /* |
| 2 | * address space "slices" (meta-segments) support |
| 3 | * |
| 4 | * Copyright (C) 2007 Benjamin Herrenschmidt, IBM Corporation. |
| 5 | * |
| 6 | * Based on hugetlb implementation |
| 7 | * |
| 8 | * Copyright (C) 2003 David Gibson, IBM Corporation. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #undef DEBUG |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/pagemap.h> |
| 30 | #include <linux/err.h> |
| 31 | #include <linux/spinlock.h> |
Paul Gortmaker | 4b16f8e | 2011-07-22 18:24:23 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Anton Blanchard | 1217d34 | 2014-08-20 08:55:19 +1000 | [diff] [blame] | 33 | #include <linux/hugetlb.h> |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 34 | #include <asm/mman.h> |
| 35 | #include <asm/mmu.h> |
Ian Munsie | be3ebfe | 2014-10-08 19:54:52 +1100 | [diff] [blame] | 36 | #include <asm/copro.h> |
Anton Blanchard | 1217d34 | 2014-08-20 08:55:19 +1000 | [diff] [blame] | 37 | #include <asm/hugetlb.h> |
Aneesh Kumar K.V | 032900e | 2018-04-10 14:21:26 +0530 | [diff] [blame] | 38 | #include <asm/mmu_context.h> |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 39 | |
Roel Kluin | f7a75f0 | 2007-10-16 23:30:25 -0700 | [diff] [blame] | 40 | static DEFINE_SPINLOCK(slice_convert_lock); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 41 | |
| 42 | #ifdef DEBUG |
| 43 | int _slice_debug = 1; |
| 44 | |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 45 | static void slice_print_mask(const char *label, const struct slice_mask *mask) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 46 | { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 47 | if (!_slice_debug) |
| 48 | return; |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 49 | pr_devel("%s low_slice: %*pbl\n", label, |
| 50 | (int)SLICE_NUM_LOW, &mask->low_slices); |
| 51 | pr_devel("%s high_slice: %*pbl\n", label, |
| 52 | (int)SLICE_NUM_HIGH, mask->high_slices); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 53 | } |
| 54 | |
Aneesh Kumar K.V | 302413c | 2017-03-22 09:06:52 +0530 | [diff] [blame] | 55 | #define slice_dbg(fmt...) do { if (_slice_debug) pr_devel(fmt); } while (0) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 56 | |
| 57 | #else |
| 58 | |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 59 | static void slice_print_mask(const char *label, const struct slice_mask *mask) {} |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 60 | #define slice_dbg(fmt...) |
| 61 | |
| 62 | #endif |
| 63 | |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 64 | static void slice_range_to_mask(unsigned long start, unsigned long len, |
| 65 | struct slice_mask *ret) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 66 | { |
| 67 | unsigned long end = start + len - 1; |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 68 | |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 69 | ret->low_slices = 0; |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 70 | if (SLICE_NUM_HIGH) |
| 71 | bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 72 | |
| 73 | if (start < SLICE_LOW_TOP) { |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 74 | unsigned long mend = min(end, |
| 75 | (unsigned long)(SLICE_LOW_TOP - 1)); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 76 | |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 77 | ret->low_slices = (1u << (GET_LOW_SLICE_INDEX(mend) + 1)) |
Aneesh Kumar K.V | 98beda7 | 2017-03-21 22:59:52 +0530 | [diff] [blame] | 78 | - (1u << GET_LOW_SLICE_INDEX(start)); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 79 | } |
| 80 | |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 81 | if ((start + len) > SLICE_LOW_TOP) { |
| 82 | unsigned long start_index = GET_HIGH_SLICE_INDEX(start); |
| 83 | unsigned long align_end = ALIGN(end, (1UL << SLICE_HIGH_SHIFT)); |
| 84 | unsigned long count = GET_HIGH_SLICE_INDEX(align_end) - start_index; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 85 | |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 86 | bitmap_set(ret->high_slices, start_index, count); |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 87 | } |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static int slice_area_is_free(struct mm_struct *mm, unsigned long addr, |
| 91 | unsigned long len) |
| 92 | { |
| 93 | struct vm_area_struct *vma; |
| 94 | |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 95 | if ((mm->context.slb_addr_limit - len) < addr) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 96 | return 0; |
| 97 | vma = find_vma(mm, addr); |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 98 | return (!vma || (addr + len) <= vm_start_gap(vma)); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice) |
| 102 | { |
| 103 | return !slice_area_is_free(mm, slice << SLICE_LOW_SHIFT, |
| 104 | 1ul << SLICE_LOW_SHIFT); |
| 105 | } |
| 106 | |
| 107 | static int slice_high_has_vma(struct mm_struct *mm, unsigned long slice) |
| 108 | { |
| 109 | unsigned long start = slice << SLICE_HIGH_SHIFT; |
| 110 | unsigned long end = start + (1ul << SLICE_HIGH_SHIFT); |
| 111 | |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 112 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 113 | /* Hack, so that each addresses is controlled by exactly one |
| 114 | * of the high or low area bitmaps, the first high area starts |
| 115 | * at 4GB, not 0 */ |
| 116 | if (start == 0) |
| 117 | start = SLICE_LOW_TOP; |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 118 | #endif |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 119 | |
| 120 | return !slice_area_is_free(mm, start, end - start); |
| 121 | } |
| 122 | |
Aneesh Kumar K.V | 7a06c66 | 2017-11-10 10:25:07 +0530 | [diff] [blame] | 123 | static void slice_mask_for_free(struct mm_struct *mm, struct slice_mask *ret, |
| 124 | unsigned long high_limit) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 125 | { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 126 | unsigned long i; |
| 127 | |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 128 | ret->low_slices = 0; |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 129 | if (SLICE_NUM_HIGH) |
| 130 | bitmap_zero(ret->high_slices, SLICE_NUM_HIGH); |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 131 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 132 | for (i = 0; i < SLICE_NUM_LOW; i++) |
| 133 | if (!slice_low_has_vma(mm, i)) |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 134 | ret->low_slices |= 1u << i; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 135 | |
Aneesh Kumar K.V | 7a06c66 | 2017-11-10 10:25:07 +0530 | [diff] [blame] | 136 | if (high_limit <= SLICE_LOW_TOP) |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 137 | return; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 138 | |
Aneesh Kumar K.V | 7a06c66 | 2017-11-10 10:25:07 +0530 | [diff] [blame] | 139 | for (i = 0; i < GET_HIGH_SLICE_INDEX(high_limit); i++) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 140 | if (!slice_high_has_vma(mm, i)) |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 141 | __set_bit(i, ret->high_slices); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 142 | } |
| 143 | |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 144 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 145 | static struct slice_mask *slice_mask_for_size(struct mm_struct *mm, int psize) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 146 | { |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 147 | #ifdef CONFIG_PPC_64K_PAGES |
| 148 | if (psize == MMU_PAGE_64K) |
| 149 | return &mm->context.mask_64k; |
| 150 | #endif |
| 151 | if (psize == MMU_PAGE_4K) |
| 152 | return &mm->context.mask_4k; |
| 153 | #ifdef CONFIG_HUGETLB_PAGE |
| 154 | if (psize == MMU_PAGE_16M) |
| 155 | return &mm->context.mask_16m; |
| 156 | if (psize == MMU_PAGE_16G) |
| 157 | return &mm->context.mask_16g; |
| 158 | #endif |
| 159 | BUG(); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 160 | } |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 161 | #elif defined(CONFIG_PPC_8xx) |
| 162 | static struct slice_mask *slice_mask_for_size(struct mm_struct *mm, int psize) |
| 163 | { |
| 164 | if (psize == mmu_virtual_psize) |
| 165 | return &mm->context.mask_base_psize; |
| 166 | #ifdef CONFIG_HUGETLB_PAGE |
| 167 | if (psize == MMU_PAGE_512K) |
| 168 | return &mm->context.mask_512k; |
| 169 | if (psize == MMU_PAGE_8M) |
| 170 | return &mm->context.mask_8m; |
| 171 | #endif |
| 172 | BUG(); |
| 173 | } |
| 174 | #else |
| 175 | #error "Must define the slice masks for page sizes supported by the platform" |
| 176 | #endif |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 177 | |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 178 | static bool slice_check_range_fits(struct mm_struct *mm, |
| 179 | const struct slice_mask *available, |
| 180 | unsigned long start, unsigned long len) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 181 | { |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 182 | unsigned long end = start + len - 1; |
| 183 | u64 low_slices = 0; |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 184 | |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 185 | if (start < SLICE_LOW_TOP) { |
| 186 | unsigned long mend = min(end, |
| 187 | (unsigned long)(SLICE_LOW_TOP - 1)); |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 188 | |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 189 | low_slices = (1u << (GET_LOW_SLICE_INDEX(mend) + 1)) |
| 190 | - (1u << GET_LOW_SLICE_INDEX(start)); |
| 191 | } |
| 192 | if ((low_slices & available->low_slices) != low_slices) |
| 193 | return false; |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 194 | |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 195 | if (SLICE_NUM_HIGH && ((start + len) > SLICE_LOW_TOP)) { |
| 196 | unsigned long start_index = GET_HIGH_SLICE_INDEX(start); |
| 197 | unsigned long align_end = ALIGN(end, (1UL << SLICE_HIGH_SHIFT)); |
| 198 | unsigned long count = GET_HIGH_SLICE_INDEX(align_end) - start_index; |
| 199 | unsigned long i; |
| 200 | |
| 201 | for (i = start_index; i < start_index + count; i++) { |
| 202 | if (!test_bit(i, available->high_slices)) |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return true; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 208 | } |
| 209 | |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 210 | static void slice_convert(struct mm_struct *mm, |
| 211 | const struct slice_mask *mask, int psize) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 212 | { |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 213 | int index, mask_index; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 214 | /* Write the new slice psize bits */ |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 215 | unsigned char *hpsizes, *lpsizes; |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 216 | struct slice_mask *psize_mask, *old_mask; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 217 | unsigned long i, flags; |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 218 | int old_psize; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 219 | |
| 220 | slice_dbg("slice_convert(mm=%p, psize=%d)\n", mm, psize); |
| 221 | slice_print_mask(" mask", mask); |
| 222 | |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 223 | psize_mask = slice_mask_for_size(mm, psize); |
| 224 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 225 | /* We need to use a spinlock here to protect against |
| 226 | * concurrent 64k -> 4k demotion ... |
| 227 | */ |
| 228 | spin_lock_irqsave(&slice_convert_lock, flags); |
| 229 | |
| 230 | lpsizes = mm->context.low_slices_psize; |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 231 | for (i = 0; i < SLICE_NUM_LOW; i++) { |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 232 | if (!(mask->low_slices & (1u << i))) |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 233 | continue; |
| 234 | |
| 235 | mask_index = i & 0x1; |
| 236 | index = i >> 1; |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 237 | |
| 238 | /* Update the slice_mask */ |
| 239 | old_psize = (lpsizes[index] >> (mask_index * 4)) & 0xf; |
| 240 | old_mask = slice_mask_for_size(mm, old_psize); |
| 241 | old_mask->low_slices &= ~(1u << i); |
| 242 | psize_mask->low_slices |= 1u << i; |
| 243 | |
| 244 | /* Update the sizes array */ |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 245 | lpsizes[index] = (lpsizes[index] & ~(0xf << (mask_index * 4))) | |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 246 | (((unsigned long)psize) << (mask_index * 4)); |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 247 | } |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 248 | |
| 249 | hpsizes = mm->context.high_slices_psize; |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 250 | for (i = 0; i < GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); i++) { |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 251 | if (!test_bit(i, mask->high_slices)) |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 252 | continue; |
| 253 | |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 254 | mask_index = i & 0x1; |
| 255 | index = i >> 1; |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 256 | |
| 257 | /* Update the slice_mask */ |
| 258 | old_psize = (hpsizes[index] >> (mask_index * 4)) & 0xf; |
| 259 | old_mask = slice_mask_for_size(mm, old_psize); |
| 260 | __clear_bit(i, old_mask->high_slices); |
| 261 | __set_bit(i, psize_mask->high_slices); |
| 262 | |
| 263 | /* Update the sizes array */ |
Nicholas Piggin | 5a807e0 | 2018-03-07 11:37:10 +1000 | [diff] [blame] | 264 | hpsizes[index] = (hpsizes[index] & ~(0xf << (mask_index * 4))) | |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 265 | (((unsigned long)psize) << (mask_index * 4)); |
| 266 | } |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 267 | |
| 268 | slice_dbg(" lsps=%lx, hsps=%lx\n", |
Aneesh Kumar K.V | 302413c | 2017-03-22 09:06:52 +0530 | [diff] [blame] | 269 | (unsigned long)mm->context.low_slices_psize, |
| 270 | (unsigned long)mm->context.high_slices_psize); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 271 | |
| 272 | spin_unlock_irqrestore(&slice_convert_lock, flags); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 273 | |
Ian Munsie | be3ebfe | 2014-10-08 19:54:52 +1100 | [diff] [blame] | 274 | copro_flush_all_slbs(mm); |
Nicholas Piggin | 8fed04d | 2018-09-15 01:30:52 +1000 | [diff] [blame] | 275 | #ifdef CONFIG_PPC64 |
| 276 | core_flush_all_slbs(mm); |
| 277 | #endif |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 278 | } |
| 279 | |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 280 | /* |
| 281 | * Compute which slice addr is part of; |
| 282 | * set *boundary_addr to the start or end boundary of that slice |
| 283 | * (depending on 'end' parameter); |
| 284 | * return boolean indicating if the slice is marked as available in the |
| 285 | * 'available' slice_mark. |
| 286 | */ |
| 287 | static bool slice_scan_available(unsigned long addr, |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 288 | const struct slice_mask *available, |
| 289 | int end, unsigned long *boundary_addr) |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 290 | { |
| 291 | unsigned long slice; |
| 292 | if (addr < SLICE_LOW_TOP) { |
| 293 | slice = GET_LOW_SLICE_INDEX(addr); |
| 294 | *boundary_addr = (slice + end) << SLICE_LOW_SHIFT; |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 295 | return !!(available->low_slices & (1u << slice)); |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 296 | } else { |
| 297 | slice = GET_HIGH_SLICE_INDEX(addr); |
| 298 | *boundary_addr = (slice + end) ? |
| 299 | ((slice + end) << SLICE_HIGH_SHIFT) : SLICE_LOW_TOP; |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 300 | return !!test_bit(slice, available->high_slices); |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 304 | static unsigned long slice_find_area_bottomup(struct mm_struct *mm, |
| 305 | unsigned long len, |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 306 | const struct slice_mask *available, |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 307 | int psize, unsigned long high_limit) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 308 | { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 309 | int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 310 | unsigned long addr, found, next_end; |
| 311 | struct vm_unmapped_area_info info; |
| 312 | |
| 313 | info.flags = 0; |
| 314 | info.length = len; |
| 315 | info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); |
| 316 | info.align_offset = 0; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 317 | |
Michel Lespinasse | 34d0717 | 2013-04-29 11:53:52 -0700 | [diff] [blame] | 318 | addr = TASK_UNMAPPED_BASE; |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 319 | /* |
| 320 | * Check till the allow max value for this mmap request |
| 321 | */ |
| 322 | while (addr < high_limit) { |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 323 | info.low_limit = addr; |
| 324 | if (!slice_scan_available(addr, available, 1, &addr)) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 325 | continue; |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 326 | |
| 327 | next_slice: |
| 328 | /* |
| 329 | * At this point [info.low_limit; addr) covers |
| 330 | * available slices only and ends at a slice boundary. |
| 331 | * Check if we need to reduce the range, or if we can |
| 332 | * extend it to cover the next available slice. |
| 333 | */ |
Aneesh Kumar K.V | be77e99 | 2017-04-14 00:48:21 +0530 | [diff] [blame] | 334 | if (addr >= high_limit) |
| 335 | addr = high_limit; |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 336 | else if (slice_scan_available(addr, available, 1, &next_end)) { |
| 337 | addr = next_end; |
| 338 | goto next_slice; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 339 | } |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 340 | info.high_limit = addr; |
| 341 | |
| 342 | found = vm_unmapped_area(&info); |
| 343 | if (!(found & ~PAGE_MASK)) |
| 344 | return found; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 345 | } |
| 346 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 347 | return -ENOMEM; |
| 348 | } |
| 349 | |
| 350 | static unsigned long slice_find_area_topdown(struct mm_struct *mm, |
| 351 | unsigned long len, |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 352 | const struct slice_mask *available, |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 353 | int psize, unsigned long high_limit) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 354 | { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 355 | int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 356 | unsigned long addr, found, prev; |
| 357 | struct vm_unmapped_area_info info; |
| 358 | |
| 359 | info.flags = VM_UNMAPPED_AREA_TOPDOWN; |
| 360 | info.length = len; |
| 361 | info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); |
| 362 | info.align_offset = 0; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 363 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 364 | addr = mm->mmap_base; |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 365 | /* |
| 366 | * If we are trying to allocate above DEFAULT_MAP_WINDOW |
| 367 | * Add the different to the mmap_base. |
| 368 | * Only for that request for which high_limit is above |
| 369 | * DEFAULT_MAP_WINDOW we should apply this. |
| 370 | */ |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 371 | if (high_limit > DEFAULT_MAP_WINDOW) |
| 372 | addr += mm->context.slb_addr_limit - DEFAULT_MAP_WINDOW; |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 373 | |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 374 | while (addr > PAGE_SIZE) { |
| 375 | info.high_limit = addr; |
| 376 | if (!slice_scan_available(addr - 1, available, 0, &addr)) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 377 | continue; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 378 | |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 379 | prev_slice: |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 380 | /* |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 381 | * At this point [addr; info.high_limit) covers |
| 382 | * available slices only and starts at a slice boundary. |
| 383 | * Check if we need to reduce the range, or if we can |
| 384 | * extend it to cover the previous available slice. |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 385 | */ |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 386 | if (addr < PAGE_SIZE) |
| 387 | addr = PAGE_SIZE; |
| 388 | else if (slice_scan_available(addr - 1, available, 0, &prev)) { |
| 389 | addr = prev; |
| 390 | goto prev_slice; |
| 391 | } |
| 392 | info.low_limit = addr; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 393 | |
Michel Lespinasse | fba2369 | 2013-04-29 11:53:53 -0700 | [diff] [blame] | 394 | found = vm_unmapped_area(&info); |
| 395 | if (!(found & ~PAGE_MASK)) |
| 396 | return found; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /* |
| 400 | * A failed mmap() very likely causes application failure, |
| 401 | * so fall back to the bottom-up function here. This scenario |
| 402 | * can happen with large stack limits and large mmap() |
| 403 | * allocations. |
| 404 | */ |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 405 | return slice_find_area_bottomup(mm, len, available, psize, high_limit); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | |
| 409 | static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 410 | const struct slice_mask *mask, int psize, |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 411 | int topdown, unsigned long high_limit) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 412 | { |
| 413 | if (topdown) |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 414 | return slice_find_area_topdown(mm, len, mask, psize, high_limit); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 415 | else |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 416 | return slice_find_area_bottomup(mm, len, mask, psize, high_limit); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 417 | } |
| 418 | |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 419 | static inline void slice_copy_mask(struct slice_mask *dst, |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 420 | const struct slice_mask *src) |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 421 | { |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 422 | dst->low_slices = src->low_slices; |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 423 | if (!SLICE_NUM_HIGH) |
| 424 | return; |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 425 | bitmap_copy(dst->high_slices, src->high_slices, SLICE_NUM_HIGH); |
| 426 | } |
| 427 | |
| 428 | static inline void slice_or_mask(struct slice_mask *dst, |
| 429 | const struct slice_mask *src1, |
| 430 | const struct slice_mask *src2) |
| 431 | { |
| 432 | dst->low_slices = src1->low_slices | src2->low_slices; |
| 433 | if (!SLICE_NUM_HIGH) |
| 434 | return; |
| 435 | bitmap_or(dst->high_slices, src1->high_slices, src2->high_slices, SLICE_NUM_HIGH); |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 438 | static inline void slice_andnot_mask(struct slice_mask *dst, |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 439 | const struct slice_mask *src1, |
| 440 | const struct slice_mask *src2) |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 441 | { |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 442 | dst->low_slices = src1->low_slices & ~src2->low_slices; |
Christophe Leroy | db3a528 | 2018-02-22 15:27:24 +0100 | [diff] [blame] | 443 | if (!SLICE_NUM_HIGH) |
| 444 | return; |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 445 | bitmap_andnot(dst->high_slices, src1->high_slices, src2->high_slices, SLICE_NUM_HIGH); |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 446 | } |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 447 | |
| 448 | #ifdef CONFIG_PPC_64K_PAGES |
| 449 | #define MMU_PAGE_BASE MMU_PAGE_64K |
| 450 | #else |
| 451 | #define MMU_PAGE_BASE MMU_PAGE_4K |
| 452 | #endif |
| 453 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 454 | unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, |
| 455 | unsigned long flags, unsigned int psize, |
Michel Lespinasse | 34d0717 | 2013-04-29 11:53:52 -0700 | [diff] [blame] | 456 | int topdown) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 457 | { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 458 | struct slice_mask good_mask; |
Aneesh Kumar K.V | f3207c1 | 2017-03-22 09:06:47 +0530 | [diff] [blame] | 459 | struct slice_mask potential_mask; |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 460 | const struct slice_mask *maskp; |
| 461 | const struct slice_mask *compat_maskp = NULL; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 462 | int fixed = (flags & MAP_FIXED); |
| 463 | int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 464 | unsigned long page_size = 1UL << pshift; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 465 | struct mm_struct *mm = current->mm; |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 466 | unsigned long newaddr; |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 467 | unsigned long high_limit; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 468 | |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 469 | high_limit = DEFAULT_MAP_WINDOW; |
Nicholas Piggin | 35602f8 | 2017-11-10 04:27:38 +1100 | [diff] [blame] | 470 | if (addr >= high_limit || (fixed && (addr + len > high_limit))) |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 471 | high_limit = TASK_SIZE; |
| 472 | |
| 473 | if (len > high_limit) |
| 474 | return -ENOMEM; |
| 475 | if (len & (page_size - 1)) |
| 476 | return -EINVAL; |
| 477 | if (fixed) { |
| 478 | if (addr & (page_size - 1)) |
| 479 | return -EINVAL; |
| 480 | if (addr > high_limit - len) |
| 481 | return -ENOMEM; |
| 482 | } |
| 483 | |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 484 | if (high_limit > mm->context.slb_addr_limit) { |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 485 | /* |
| 486 | * Increasing the slb_addr_limit does not require |
| 487 | * slice mask cache to be recalculated because it should |
| 488 | * be already initialised beyond the old address limit. |
| 489 | */ |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 490 | mm->context.slb_addr_limit = high_limit; |
Nicholas Piggin | 8fed04d | 2018-09-15 01:30:52 +1000 | [diff] [blame] | 491 | #ifdef CONFIG_PPC64 |
| 492 | core_flush_all_slbs(mm); |
| 493 | #endif |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 494 | } |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 495 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 496 | /* Sanity checks */ |
| 497 | BUG_ON(mm->task_size == 0); |
Nicholas Piggin | 4722476 | 2017-11-10 04:27:40 +1100 | [diff] [blame] | 498 | BUG_ON(mm->context.slb_addr_limit == 0); |
Aneesh Kumar K.V | 764041e | 2016-04-29 23:26:09 +1000 | [diff] [blame] | 499 | VM_BUG_ON(radix_enabled()); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 500 | |
| 501 | slice_dbg("slice_get_unmapped_area(mm=%p, psize=%d...\n", mm, psize); |
Michel Lespinasse | 34d0717 | 2013-04-29 11:53:52 -0700 | [diff] [blame] | 502 | slice_dbg(" addr=%lx, len=%lx, flags=%lx, topdown=%d\n", |
| 503 | addr, len, flags, topdown); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 504 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 505 | /* If hint, make sure it matches our alignment restrictions */ |
| 506 | if (!fixed && addr) { |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 507 | addr = _ALIGN_UP(addr, page_size); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 508 | slice_dbg(" aligned addr=%lx\n", addr); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 509 | /* Ignore hint if it's too large or overlaps a VMA */ |
Nicholas Piggin | 6a72dc0 | 2017-11-10 04:27:36 +1100 | [diff] [blame] | 510 | if (addr > high_limit - len || |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 511 | !slice_area_is_free(mm, addr, len)) |
| 512 | addr = 0; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 513 | } |
| 514 | |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 515 | /* First make up a "good" mask of slices that have the right size |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 516 | * already |
| 517 | */ |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 518 | maskp = slice_mask_for_size(mm, psize); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 519 | |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 520 | /* |
| 521 | * Here "good" means slices that are already the right page size, |
| 522 | * "compat" means slices that have a compatible page size (i.e. |
| 523 | * 4k in a 64k pagesize kernel), and "free" means slices without |
| 524 | * any VMAs. |
| 525 | * |
| 526 | * If MAP_FIXED: |
| 527 | * check if fits in good | compat => OK |
| 528 | * check if fits in good | compat | free => convert free |
| 529 | * else bad |
| 530 | * If have hint: |
| 531 | * check if hint fits in good => OK |
| 532 | * check if hint fits in good | free => convert free |
| 533 | * Otherwise: |
| 534 | * search in good, found => OK |
| 535 | * search in good | free, found => convert free |
| 536 | * search in good | compat | free, found => convert free. |
| 537 | */ |
| 538 | |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 539 | /* |
| 540 | * If we support combo pages, we can allow 64k pages in 4k slices |
| 541 | * The mask copies could be avoided in most cases here if we had |
| 542 | * a pointer to good mask for the next code to use. |
| 543 | */ |
| 544 | if (IS_ENABLED(CONFIG_PPC_64K_PAGES) && psize == MMU_PAGE_64K) { |
| 545 | compat_maskp = slice_mask_for_size(mm, MMU_PAGE_4K); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 546 | if (fixed) |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 547 | slice_or_mask(&good_mask, maskp, compat_maskp); |
| 548 | else |
| 549 | slice_copy_mask(&good_mask, maskp); |
| 550 | } else { |
| 551 | slice_copy_mask(&good_mask, maskp); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 552 | } |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 553 | |
| 554 | slice_print_mask(" good_mask", &good_mask); |
| 555 | if (compat_maskp) |
| 556 | slice_print_mask(" compat_mask", compat_maskp); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 557 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 558 | /* First check hint if it's valid or if we have MAP_FIXED */ |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 559 | if (addr != 0 || fixed) { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 560 | /* Check if we fit in the good mask. If we do, we just return, |
| 561 | * nothing else to do |
| 562 | */ |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 563 | if (slice_check_range_fits(mm, &good_mask, addr, len)) { |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 564 | slice_dbg(" fits good !\n"); |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 565 | newaddr = addr; |
| 566 | goto return_addr; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 567 | } |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 568 | } else { |
| 569 | /* Now let's see if we can find something in the existing |
| 570 | * slices for that size |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 571 | */ |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 572 | newaddr = slice_find_area(mm, len, &good_mask, |
Aneesh Kumar K.V | f4ea6dc | 2017-03-30 16:35:21 +0530 | [diff] [blame] | 573 | psize, topdown, high_limit); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 574 | if (newaddr != -ENOMEM) { |
| 575 | /* Found within the good mask, we don't have to setup, |
| 576 | * we thus return directly |
| 577 | */ |
| 578 | slice_dbg(" found area at 0x%lx\n", newaddr); |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 579 | goto return_addr; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 580 | } |
| 581 | } |
Aneesh Kumar K.V | 7a06c66 | 2017-11-10 10:25:07 +0530 | [diff] [blame] | 582 | /* |
| 583 | * We don't fit in the good mask, check what other slices are |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 584 | * empty and thus can be converted |
| 585 | */ |
Aneesh Kumar K.V | 7a06c66 | 2017-11-10 10:25:07 +0530 | [diff] [blame] | 586 | slice_mask_for_free(mm, &potential_mask, high_limit); |
Nicholas Piggin | b8c9354 | 2018-03-07 11:37:14 +1000 | [diff] [blame] | 587 | slice_or_mask(&potential_mask, &potential_mask, &good_mask); |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 588 | slice_print_mask(" potential", &potential_mask); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 589 | |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 590 | if (addr != 0 || fixed) { |
| 591 | if (slice_check_range_fits(mm, &potential_mask, addr, len)) { |
| 592 | slice_dbg(" fits potential !\n"); |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 593 | newaddr = addr; |
Nicholas Piggin | ae3066b | 2018-03-07 11:37:13 +1000 | [diff] [blame] | 594 | goto convert; |
| 595 | } |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /* If we have MAP_FIXED and failed the above steps, then error out */ |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 599 | if (fixed) |
| 600 | return -EBUSY; |
| 601 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 602 | slice_dbg(" search...\n"); |
| 603 | |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 604 | /* If we had a hint that didn't work out, see if we can fit |
| 605 | * anywhere in the good area. |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 606 | */ |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 607 | if (addr) { |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 608 | newaddr = slice_find_area(mm, len, &good_mask, |
| 609 | psize, topdown, high_limit); |
| 610 | if (newaddr != -ENOMEM) { |
| 611 | slice_dbg(" found area at 0x%lx\n", newaddr); |
| 612 | goto return_addr; |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 613 | } |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* Now let's see if we can find something in the existing slices |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 617 | * for that size plus free slices |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 618 | */ |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 619 | newaddr = slice_find_area(mm, len, &potential_mask, |
| 620 | psize, topdown, high_limit); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 621 | |
| 622 | #ifdef CONFIG_PPC_64K_PAGES |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 623 | if (newaddr == -ENOMEM && psize == MMU_PAGE_64K) { |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 624 | /* retry the search with 4k-page slices included */ |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 625 | slice_or_mask(&potential_mask, &potential_mask, compat_maskp); |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 626 | newaddr = slice_find_area(mm, len, &potential_mask, |
| 627 | psize, topdown, high_limit); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 628 | } |
| 629 | #endif |
| 630 | |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 631 | if (newaddr == -ENOMEM) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 632 | return -ENOMEM; |
| 633 | |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 634 | slice_range_to_mask(newaddr, len, &potential_mask); |
| 635 | slice_dbg(" found potential area at 0x%lx\n", newaddr); |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 636 | slice_print_mask(" mask", &potential_mask); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 637 | |
| 638 | convert: |
Aneesh Kumar K.V | f384796c | 2018-03-26 15:34:48 +0530 | [diff] [blame] | 639 | /* |
| 640 | * Try to allocate the context before we do slice convert |
| 641 | * so that we handle the context allocation failure gracefully. |
| 642 | */ |
| 643 | if (need_extra_context(mm, newaddr)) { |
| 644 | if (alloc_extended_context(mm, newaddr) < 0) |
| 645 | return -ENOMEM; |
| 646 | } |
| 647 | |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 648 | slice_andnot_mask(&potential_mask, &potential_mask, &good_mask); |
| 649 | if (compat_maskp && !fixed) |
| 650 | slice_andnot_mask(&potential_mask, &potential_mask, compat_maskp); |
| 651 | if (potential_mask.low_slices || |
| 652 | (SLICE_NUM_HIGH && |
| 653 | !bitmap_empty(potential_mask.high_slices, SLICE_NUM_HIGH))) { |
| 654 | slice_convert(mm, &potential_mask, psize); |
Nicholas Piggin | 8fed04d | 2018-09-15 01:30:52 +1000 | [diff] [blame] | 655 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 656 | if (psize > MMU_PAGE_BASE) |
Nicholas Piggin | 8fed04d | 2018-09-15 01:30:52 +1000 | [diff] [blame] | 657 | core_flush_all_slbs(mm); |
| 658 | #endif |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 659 | } |
Aneesh Kumar K.V | 0dea04b | 2018-03-26 15:34:47 +0530 | [diff] [blame] | 660 | return newaddr; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 661 | |
Aneesh Kumar K.V | f384796c | 2018-03-26 15:34:48 +0530 | [diff] [blame] | 662 | return_addr: |
| 663 | if (need_extra_context(mm, newaddr)) { |
| 664 | if (alloc_extended_context(mm, newaddr) < 0) |
| 665 | return -ENOMEM; |
| 666 | } |
| 667 | return newaddr; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 668 | } |
| 669 | EXPORT_SYMBOL_GPL(slice_get_unmapped_area); |
| 670 | |
| 671 | unsigned long arch_get_unmapped_area(struct file *filp, |
| 672 | unsigned long addr, |
| 673 | unsigned long len, |
| 674 | unsigned long pgoff, |
| 675 | unsigned long flags) |
| 676 | { |
| 677 | return slice_get_unmapped_area(addr, len, flags, |
Michel Lespinasse | 34d0717 | 2013-04-29 11:53:52 -0700 | [diff] [blame] | 678 | current->mm->context.user_psize, 0); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | unsigned long arch_get_unmapped_area_topdown(struct file *filp, |
| 682 | const unsigned long addr0, |
| 683 | const unsigned long len, |
| 684 | const unsigned long pgoff, |
| 685 | const unsigned long flags) |
| 686 | { |
| 687 | return slice_get_unmapped_area(addr0, len, flags, |
Michel Lespinasse | 34d0717 | 2013-04-29 11:53:52 -0700 | [diff] [blame] | 688 | current->mm->context.user_psize, 1); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr) |
| 692 | { |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 693 | unsigned char *psizes; |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 694 | int index, mask_index; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 695 | |
Nicholas Piggin | 014a32b | 2018-03-07 11:37:17 +1000 | [diff] [blame] | 696 | VM_BUG_ON(radix_enabled()); |
| 697 | |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 698 | if (addr < SLICE_LOW_TOP) { |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 699 | psizes = mm->context.low_slices_psize; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 700 | index = GET_LOW_SLICE_INDEX(addr); |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 701 | } else { |
| 702 | psizes = mm->context.high_slices_psize; |
| 703 | index = GET_HIGH_SLICE_INDEX(addr); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 704 | } |
Aneesh Kumar K.V | 7aa0727 | 2012-09-10 02:52:52 +0000 | [diff] [blame] | 705 | mask_index = index & 0x1; |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 706 | return (psizes[index >> 1] >> (mask_index * 4)) & 0xf; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 707 | } |
| 708 | EXPORT_SYMBOL_GPL(get_slice_psize); |
| 709 | |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 710 | void slice_init_new_context_exec(struct mm_struct *mm) |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 711 | { |
Christophe Leroy | 1547242 | 2018-02-22 15:27:28 +0100 | [diff] [blame] | 712 | unsigned char *hpsizes, *lpsizes; |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 713 | struct slice_mask *mask; |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 714 | unsigned int psize = mmu_virtual_psize; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 715 | |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 716 | slice_dbg("slice_init_new_context_exec(mm=%p)\n", mm); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 717 | |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 718 | /* |
| 719 | * In the case of exec, use the default limit. In the |
| 720 | * case of fork it is just inherited from the mm being |
| 721 | * duplicated. |
| 722 | */ |
| 723 | #ifdef CONFIG_PPC64 |
| 724 | mm->context.slb_addr_limit = DEFAULT_MAP_WINDOW_USER64; |
| 725 | #else |
| 726 | mm->context.slb_addr_limit = DEFAULT_MAP_WINDOW; |
| 727 | #endif |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 728 | |
| 729 | mm->context.user_psize = psize; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 730 | |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 731 | /* |
| 732 | * Set all slice psizes to the default. |
| 733 | */ |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 734 | lpsizes = mm->context.low_slices_psize; |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 735 | memset(lpsizes, (psize << 4) | psize, SLICE_NUM_LOW >> 1); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 736 | |
| 737 | hpsizes = mm->context.high_slices_psize; |
Nicholas Piggin | 1753dd1 | 2018-03-07 11:37:09 +1000 | [diff] [blame] | 738 | memset(hpsizes, (psize << 4) | psize, SLICE_NUM_HIGH >> 1); |
Nicholas Piggin | 5709f7c | 2018-03-07 11:37:12 +1000 | [diff] [blame] | 739 | |
| 740 | /* |
| 741 | * Slice mask cache starts zeroed, fill the default size cache. |
| 742 | */ |
| 743 | mask = slice_mask_for_size(mm, psize); |
| 744 | mask->low_slices = ~0UL; |
| 745 | if (SLICE_NUM_HIGH) |
| 746 | bitmap_fill(mask->high_slices, SLICE_NUM_HIGH); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 747 | } |
| 748 | |
Nicholas Piggin | 2e16267 | 2018-09-15 01:30:55 +1000 | [diff] [blame] | 749 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 750 | void slice_setup_new_exec(void) |
| 751 | { |
| 752 | struct mm_struct *mm = current->mm; |
| 753 | |
| 754 | slice_dbg("slice_setup_new_exec(mm=%p)\n", mm); |
| 755 | |
| 756 | if (!is_32bit_task()) |
| 757 | return; |
| 758 | |
| 759 | mm->context.slb_addr_limit = DEFAULT_MAP_WINDOW; |
| 760 | } |
| 761 | #endif |
| 762 | |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 763 | void slice_set_range_psize(struct mm_struct *mm, unsigned long start, |
| 764 | unsigned long len, unsigned int psize) |
| 765 | { |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 766 | struct slice_mask mask; |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 767 | |
Aneesh Kumar K.V | 764041e | 2016-04-29 23:26:09 +1000 | [diff] [blame] | 768 | VM_BUG_ON(radix_enabled()); |
Aneesh Kumar K.V | a4d36215 | 2017-03-22 09:06:48 +0530 | [diff] [blame] | 769 | |
| 770 | slice_range_to_mask(start, len, &mask); |
Nicholas Piggin | 830fd2d | 2018-03-07 11:37:11 +1000 | [diff] [blame] | 771 | slice_convert(mm, &mask, psize); |
Paul Mackerras | 3a8247c | 2008-06-18 15:29:12 +1000 | [diff] [blame] | 772 | } |
| 773 | |
Aneesh Kumar K.V | 6643773 | 2014-10-21 14:25:38 +1100 | [diff] [blame] | 774 | #ifdef CONFIG_HUGETLB_PAGE |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 775 | /* |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 776 | * is_hugepage_only_range() is used by generic code to verify whether |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 777 | * a normal mmap mapping (non hugetlbfs) is valid on a given area. |
| 778 | * |
| 779 | * until the generic code provides a more generic hook and/or starts |
| 780 | * calling arch get_unmapped_area for MAP_FIXED (which our implementation |
| 781 | * here knows how to deal with), we hijack it to keep standard mappings |
| 782 | * away from us. |
| 783 | * |
| 784 | * because of that generic code limitation, MAP_FIXED mapping cannot |
| 785 | * "convert" back a slice with no VMAs to the standard page size, only |
| 786 | * get_unmapped_area() can. It would be possible to fix it here but I |
| 787 | * prefer working on fixing the generic code instead. |
| 788 | * |
| 789 | * WARNING: This will not work if hugetlbfs isn't enabled since the |
| 790 | * generic code will redefine that function as 0 in that. This is ok |
| 791 | * for now as we only use slices with hugetlbfs enabled. This should |
| 792 | * be fixed as the generic code gets fixed. |
| 793 | */ |
Nicholas Piggin | 014a32b | 2018-03-07 11:37:17 +1000 | [diff] [blame] | 794 | int slice_is_hugepage_only_range(struct mm_struct *mm, unsigned long addr, |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 795 | unsigned long len) |
| 796 | { |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 797 | const struct slice_mask *maskp; |
Dave Kleikamp | 9ba0fdb | 2009-01-14 09:09:34 +0000 | [diff] [blame] | 798 | unsigned int psize = mm->context.user_psize; |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 799 | |
Nicholas Piggin | 014a32b | 2018-03-07 11:37:17 +1000 | [diff] [blame] | 800 | VM_BUG_ON(radix_enabled()); |
Aneesh Kumar K.V | 764041e | 2016-04-29 23:26:09 +1000 | [diff] [blame] | 801 | |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 802 | maskp = slice_mask_for_size(mm, psize); |
Dave Kleikamp | 9ba0fdb | 2009-01-14 09:09:34 +0000 | [diff] [blame] | 803 | #ifdef CONFIG_PPC_64K_PAGES |
| 804 | /* We need to account for 4k slices too */ |
| 805 | if (psize == MMU_PAGE_64K) { |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 806 | const struct slice_mask *compat_maskp; |
| 807 | struct slice_mask available; |
| 808 | |
| 809 | compat_maskp = slice_mask_for_size(mm, MMU_PAGE_4K); |
| 810 | slice_or_mask(&available, maskp, compat_maskp); |
| 811 | return !slice_check_range_fits(mm, &available, addr, len); |
Dave Kleikamp | 9ba0fdb | 2009-01-14 09:09:34 +0000 | [diff] [blame] | 812 | } |
| 813 | #endif |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 814 | |
Nicholas Piggin | d262bd5 | 2018-03-07 11:37:16 +1000 | [diff] [blame] | 815 | return !slice_check_range_fits(mm, maskp, addr, len); |
Benjamin Herrenschmidt | d0f13e3 | 2007-05-08 16:27:27 +1000 | [diff] [blame] | 816 | } |
Aneesh Kumar K.V | 6643773 | 2014-10-21 14:25:38 +1100 | [diff] [blame] | 817 | #endif |