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