slice.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. #undef DEBUG
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/err.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/export.h>
  31. #include <linux/hugetlb.h>
  32. #include <asm/mman.h>
  33. #include <asm/mmu.h>
  34. #include <asm/copro.h>
  35. #include <asm/hugetlb.h>
  36. /* some sanity checks */
  37. #if (PGTABLE_RANGE >> 43) > SLICE_MASK_SIZE
  38. #error PGTABLE_RANGE exceeds slice_mask high_slices size
  39. #endif
  40. static DEFINE_SPINLOCK(slice_convert_lock);
  41. #ifdef DEBUG
  42. int _slice_debug = 1;
  43. static void slice_print_mask(const char *label, struct slice_mask mask)
  44. {
  45. char *p, buf[16 + 3 + 64 + 1];
  46. int i;
  47. if (!_slice_debug)
  48. return;
  49. p = buf;
  50. for (i = 0; i < SLICE_NUM_LOW; i++)
  51. *(p++) = (mask.low_slices & (1 << i)) ? '1' : '0';
  52. *(p++) = ' ';
  53. *(p++) = '-';
  54. *(p++) = ' ';
  55. for (i = 0; i < SLICE_NUM_HIGH; i++)
  56. *(p++) = (mask.high_slices & (1ul << i)) ? '1' : '0';
  57. *(p++) = 0;
  58. printk(KERN_DEBUG "%s:%s\n", label, buf);
  59. }
  60. #define slice_dbg(fmt...) do { if (_slice_debug) pr_debug(fmt); } while(0)
  61. #else
  62. static void slice_print_mask(const char *label, struct slice_mask mask) {}
  63. #define slice_dbg(fmt...)
  64. #endif
  65. static struct slice_mask slice_range_to_mask(unsigned long start,
  66. unsigned long len)
  67. {
  68. unsigned long end = start + len - 1;
  69. struct slice_mask ret = { 0, 0 };
  70. if (start < SLICE_LOW_TOP) {
  71. unsigned long mend = min(end, SLICE_LOW_TOP);
  72. unsigned long mstart = min(start, SLICE_LOW_TOP);
  73. ret.low_slices = (1u << (GET_LOW_SLICE_INDEX(mend) + 1))
  74. - (1u << GET_LOW_SLICE_INDEX(mstart));
  75. }
  76. if ((start + len) > SLICE_LOW_TOP)
  77. ret.high_slices = (1ul << (GET_HIGH_SLICE_INDEX(end) + 1))
  78. - (1ul << GET_HIGH_SLICE_INDEX(start));
  79. return ret;
  80. }
  81. static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
  82. unsigned long len)
  83. {
  84. struct vm_area_struct *vma;
  85. if ((mm->task_size - len) < addr)
  86. return 0;
  87. vma = find_vma(mm, addr);
  88. return (!vma || (addr + len) <= vma->vm_start);
  89. }
  90. static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
  91. {
  92. return !slice_area_is_free(mm, slice << SLICE_LOW_SHIFT,
  93. 1ul << SLICE_LOW_SHIFT);
  94. }
  95. static int slice_high_has_vma(struct mm_struct *mm, unsigned long slice)
  96. {
  97. unsigned long start = slice << SLICE_HIGH_SHIFT;
  98. unsigned long end = start + (1ul << SLICE_HIGH_SHIFT);
  99. /* Hack, so that each addresses is controlled by exactly one
  100. * of the high or low area bitmaps, the first high area starts
  101. * at 4GB, not 0 */
  102. if (start == 0)
  103. start = SLICE_LOW_TOP;
  104. return !slice_area_is_free(mm, start, end - start);
  105. }
  106. static struct slice_mask slice_mask_for_free(struct mm_struct *mm)
  107. {
  108. struct slice_mask ret = { 0, 0 };
  109. unsigned long i;
  110. for (i = 0; i < SLICE_NUM_LOW; i++)
  111. if (!slice_low_has_vma(mm, i))
  112. ret.low_slices |= 1u << i;
  113. if (mm->task_size <= SLICE_LOW_TOP)
  114. return ret;
  115. for (i = 0; i < SLICE_NUM_HIGH; i++)
  116. if (!slice_high_has_vma(mm, i))
  117. ret.high_slices |= 1ul << i;
  118. return ret;
  119. }
  120. static struct slice_mask slice_mask_for_size(struct mm_struct *mm, int psize)
  121. {
  122. unsigned char *hpsizes;
  123. int index, mask_index;
  124. struct slice_mask ret = { 0, 0 };
  125. unsigned long i;
  126. u64 lpsizes;
  127. lpsizes = mm->context.low_slices_psize;
  128. for (i = 0; i < SLICE_NUM_LOW; i++)
  129. if (((lpsizes >> (i * 4)) & 0xf) == psize)
  130. ret.low_slices |= 1u << i;
  131. hpsizes = mm->context.high_slices_psize;
  132. for (i = 0; i < SLICE_NUM_HIGH; i++) {
  133. mask_index = i & 0x1;
  134. index = i >> 1;
  135. if (((hpsizes[index] >> (mask_index * 4)) & 0xf) == psize)
  136. ret.high_slices |= 1ul << i;
  137. }
  138. return ret;
  139. }
  140. static int slice_check_fit(struct slice_mask mask, struct slice_mask available)
  141. {
  142. return (mask.low_slices & available.low_slices) == mask.low_slices &&
  143. (mask.high_slices & available.high_slices) == mask.high_slices;
  144. }
  145. static void slice_flush_segments(void *parm)
  146. {
  147. struct mm_struct *mm = parm;
  148. unsigned long flags;
  149. if (mm != current->active_mm)
  150. return;
  151. copy_mm_to_paca(&current->active_mm->context);
  152. local_irq_save(flags);
  153. slb_flush_and_rebolt();
  154. local_irq_restore(flags);
  155. }
  156. static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psize)
  157. {
  158. int index, mask_index;
  159. /* Write the new slice psize bits */
  160. unsigned char *hpsizes;
  161. u64 lpsizes;
  162. unsigned long i, flags;
  163. slice_dbg("slice_convert(mm=%p, psize=%d)\n", mm, psize);
  164. slice_print_mask(" mask", mask);
  165. /* We need to use a spinlock here to protect against
  166. * concurrent 64k -> 4k demotion ...
  167. */
  168. spin_lock_irqsave(&slice_convert_lock, flags);
  169. lpsizes = mm->context.low_slices_psize;
  170. for (i = 0; i < SLICE_NUM_LOW; i++)
  171. if (mask.low_slices & (1u << i))
  172. lpsizes = (lpsizes & ~(0xful << (i * 4))) |
  173. (((unsigned long)psize) << (i * 4));
  174. /* Assign the value back */
  175. mm->context.low_slices_psize = lpsizes;
  176. hpsizes = mm->context.high_slices_psize;
  177. for (i = 0; i < SLICE_NUM_HIGH; i++) {
  178. mask_index = i & 0x1;
  179. index = i >> 1;
  180. if (mask.high_slices & (1ul << i))
  181. hpsizes[index] = (hpsizes[index] &
  182. ~(0xf << (mask_index * 4))) |
  183. (((unsigned long)psize) << (mask_index * 4));
  184. }
  185. slice_dbg(" lsps=%lx, hsps=%lx\n",
  186. mm->context.low_slices_psize,
  187. mm->context.high_slices_psize);
  188. spin_unlock_irqrestore(&slice_convert_lock, flags);
  189. copro_flush_all_slbs(mm);
  190. }
  191. /*
  192. * Compute which slice addr is part of;
  193. * set *boundary_addr to the start or end boundary of that slice
  194. * (depending on 'end' parameter);
  195. * return boolean indicating if the slice is marked as available in the
  196. * 'available' slice_mark.
  197. */
  198. static bool slice_scan_available(unsigned long addr,
  199. struct slice_mask available,
  200. int end,
  201. unsigned long *boundary_addr)
  202. {
  203. unsigned long slice;
  204. if (addr < SLICE_LOW_TOP) {
  205. slice = GET_LOW_SLICE_INDEX(addr);
  206. *boundary_addr = (slice + end) << SLICE_LOW_SHIFT;
  207. return !!(available.low_slices & (1u << slice));
  208. } else {
  209. slice = GET_HIGH_SLICE_INDEX(addr);
  210. *boundary_addr = (slice + end) ?
  211. ((slice + end) << SLICE_HIGH_SHIFT) : SLICE_LOW_TOP;
  212. return !!(available.high_slices & (1ul << slice));
  213. }
  214. }
  215. static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
  216. unsigned long len,
  217. struct slice_mask available,
  218. int psize)
  219. {
  220. int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
  221. unsigned long addr, found, next_end;
  222. struct vm_unmapped_area_info info;
  223. info.flags = 0;
  224. info.length = len;
  225. info.align_mask = PAGE_MASK & ((1ul << pshift) - 1);
  226. info.align_offset = 0;
  227. addr = TASK_UNMAPPED_BASE;
  228. while (addr < TASK_SIZE) {
  229. info.low_limit = addr;
  230. if (!slice_scan_available(addr, available, 1, &addr))
  231. continue;
  232. next_slice:
  233. /*
  234. * At this point [info.low_limit; addr) covers
  235. * available slices only and ends at a slice boundary.
  236. * Check if we need to reduce the range, or if we can
  237. * extend it to cover the next available slice.
  238. */
  239. if (addr >= TASK_SIZE)
  240. addr = TASK_SIZE;
  241. else if (slice_scan_available(addr, available, 1, &next_end)) {
  242. addr = next_end;
  243. goto next_slice;
  244. }
  245. info.high_limit = addr;
  246. found = vm_unmapped_area(&info);
  247. if (!(found & ~PAGE_MASK))
  248. return found;
  249. }
  250. return -ENOMEM;
  251. }
  252. static unsigned long slice_find_area_topdown(struct mm_struct *mm,
  253. unsigned long len,
  254. struct slice_mask available,
  255. int psize)
  256. {
  257. int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
  258. unsigned long addr, found, prev;
  259. struct vm_unmapped_area_info info;
  260. info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  261. info.length = len;
  262. info.align_mask = PAGE_MASK & ((1ul << pshift) - 1);
  263. info.align_offset = 0;
  264. addr = mm->mmap_base;
  265. while (addr > PAGE_SIZE) {
  266. info.high_limit = addr;
  267. if (!slice_scan_available(addr - 1, available, 0, &addr))
  268. continue;
  269. prev_slice:
  270. /*
  271. * At this point [addr; info.high_limit) covers
  272. * available slices only and starts at a slice boundary.
  273. * Check if we need to reduce the range, or if we can
  274. * extend it to cover the previous available slice.
  275. */
  276. if (addr < PAGE_SIZE)
  277. addr = PAGE_SIZE;
  278. else if (slice_scan_available(addr - 1, available, 0, &prev)) {
  279. addr = prev;
  280. goto prev_slice;
  281. }
  282. info.low_limit = addr;
  283. found = vm_unmapped_area(&info);
  284. if (!(found & ~PAGE_MASK))
  285. return found;
  286. }
  287. /*
  288. * A failed mmap() very likely causes application failure,
  289. * so fall back to the bottom-up function here. This scenario
  290. * can happen with large stack limits and large mmap()
  291. * allocations.
  292. */
  293. return slice_find_area_bottomup(mm, len, available, psize);
  294. }
  295. static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len,
  296. struct slice_mask mask, int psize,
  297. int topdown)
  298. {
  299. if (topdown)
  300. return slice_find_area_topdown(mm, len, mask, psize);
  301. else
  302. return slice_find_area_bottomup(mm, len, mask, psize);
  303. }
  304. #define or_mask(dst, src) do { \
  305. (dst).low_slices |= (src).low_slices; \
  306. (dst).high_slices |= (src).high_slices; \
  307. } while (0)
  308. #define andnot_mask(dst, src) do { \
  309. (dst).low_slices &= ~(src).low_slices; \
  310. (dst).high_slices &= ~(src).high_slices; \
  311. } while (0)
  312. #ifdef CONFIG_PPC_64K_PAGES
  313. #define MMU_PAGE_BASE MMU_PAGE_64K
  314. #else
  315. #define MMU_PAGE_BASE MMU_PAGE_4K
  316. #endif
  317. unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
  318. unsigned long flags, unsigned int psize,
  319. int topdown)
  320. {
  321. struct slice_mask mask = {0, 0};
  322. struct slice_mask good_mask;
  323. struct slice_mask potential_mask = {0,0} /* silence stupid warning */;
  324. struct slice_mask compat_mask = {0, 0};
  325. int fixed = (flags & MAP_FIXED);
  326. int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
  327. struct mm_struct *mm = current->mm;
  328. unsigned long newaddr;
  329. /* Sanity checks */
  330. BUG_ON(mm->task_size == 0);
  331. slice_dbg("slice_get_unmapped_area(mm=%p, psize=%d...\n", mm, psize);
  332. slice_dbg(" addr=%lx, len=%lx, flags=%lx, topdown=%d\n",
  333. addr, len, flags, topdown);
  334. if (len > mm->task_size)
  335. return -ENOMEM;
  336. if (len & ((1ul << pshift) - 1))
  337. return -EINVAL;
  338. if (fixed && (addr & ((1ul << pshift) - 1)))
  339. return -EINVAL;
  340. if (fixed && addr > (mm->task_size - len))
  341. return -ENOMEM;
  342. /* If hint, make sure it matches our alignment restrictions */
  343. if (!fixed && addr) {
  344. addr = _ALIGN_UP(addr, 1ul << pshift);
  345. slice_dbg(" aligned addr=%lx\n", addr);
  346. /* Ignore hint if it's too large or overlaps a VMA */
  347. if (addr > mm->task_size - len ||
  348. !slice_area_is_free(mm, addr, len))
  349. addr = 0;
  350. }
  351. /* First make up a "good" mask of slices that have the right size
  352. * already
  353. */
  354. good_mask = slice_mask_for_size(mm, psize);
  355. slice_print_mask(" good_mask", good_mask);
  356. /*
  357. * Here "good" means slices that are already the right page size,
  358. * "compat" means slices that have a compatible page size (i.e.
  359. * 4k in a 64k pagesize kernel), and "free" means slices without
  360. * any VMAs.
  361. *
  362. * If MAP_FIXED:
  363. * check if fits in good | compat => OK
  364. * check if fits in good | compat | free => convert free
  365. * else bad
  366. * If have hint:
  367. * check if hint fits in good => OK
  368. * check if hint fits in good | free => convert free
  369. * Otherwise:
  370. * search in good, found => OK
  371. * search in good | free, found => convert free
  372. * search in good | compat | free, found => convert free.
  373. */
  374. #ifdef CONFIG_PPC_64K_PAGES
  375. /* If we support combo pages, we can allow 64k pages in 4k slices */
  376. if (psize == MMU_PAGE_64K) {
  377. compat_mask = slice_mask_for_size(mm, MMU_PAGE_4K);
  378. if (fixed)
  379. or_mask(good_mask, compat_mask);
  380. }
  381. #endif
  382. /* First check hint if it's valid or if we have MAP_FIXED */
  383. if (addr != 0 || fixed) {
  384. /* Build a mask for the requested range */
  385. mask = slice_range_to_mask(addr, len);
  386. slice_print_mask(" mask", mask);
  387. /* Check if we fit in the good mask. If we do, we just return,
  388. * nothing else to do
  389. */
  390. if (slice_check_fit(mask, good_mask)) {
  391. slice_dbg(" fits good !\n");
  392. return addr;
  393. }
  394. } else {
  395. /* Now let's see if we can find something in the existing
  396. * slices for that size
  397. */
  398. newaddr = slice_find_area(mm, len, good_mask, psize, topdown);
  399. if (newaddr != -ENOMEM) {
  400. /* Found within the good mask, we don't have to setup,
  401. * we thus return directly
  402. */
  403. slice_dbg(" found area at 0x%lx\n", newaddr);
  404. return newaddr;
  405. }
  406. }
  407. /* We don't fit in the good mask, check what other slices are
  408. * empty and thus can be converted
  409. */
  410. potential_mask = slice_mask_for_free(mm);
  411. or_mask(potential_mask, good_mask);
  412. slice_print_mask(" potential", potential_mask);
  413. if ((addr != 0 || fixed) && slice_check_fit(mask, potential_mask)) {
  414. slice_dbg(" fits potential !\n");
  415. goto convert;
  416. }
  417. /* If we have MAP_FIXED and failed the above steps, then error out */
  418. if (fixed)
  419. return -EBUSY;
  420. slice_dbg(" search...\n");
  421. /* If we had a hint that didn't work out, see if we can fit
  422. * anywhere in the good area.
  423. */
  424. if (addr) {
  425. addr = slice_find_area(mm, len, good_mask, psize, topdown);
  426. if (addr != -ENOMEM) {
  427. slice_dbg(" found area at 0x%lx\n", addr);
  428. return addr;
  429. }
  430. }
  431. /* Now let's see if we can find something in the existing slices
  432. * for that size plus free slices
  433. */
  434. addr = slice_find_area(mm, len, potential_mask, psize, topdown);
  435. #ifdef CONFIG_PPC_64K_PAGES
  436. if (addr == -ENOMEM && psize == MMU_PAGE_64K) {
  437. /* retry the search with 4k-page slices included */
  438. or_mask(potential_mask, compat_mask);
  439. addr = slice_find_area(mm, len, potential_mask, psize,
  440. topdown);
  441. }
  442. #endif
  443. if (addr == -ENOMEM)
  444. return -ENOMEM;
  445. mask = slice_range_to_mask(addr, len);
  446. slice_dbg(" found potential area at 0x%lx\n", addr);
  447. slice_print_mask(" mask", mask);
  448. convert:
  449. andnot_mask(mask, good_mask);
  450. andnot_mask(mask, compat_mask);
  451. if (mask.low_slices || mask.high_slices) {
  452. slice_convert(mm, mask, psize);
  453. if (psize > MMU_PAGE_BASE)
  454. on_each_cpu(slice_flush_segments, mm, 1);
  455. }
  456. return addr;
  457. }
  458. EXPORT_SYMBOL_GPL(slice_get_unmapped_area);
  459. unsigned long arch_get_unmapped_area(struct file *filp,
  460. unsigned long addr,
  461. unsigned long len,
  462. unsigned long pgoff,
  463. unsigned long flags)
  464. {
  465. return slice_get_unmapped_area(addr, len, flags,
  466. current->mm->context.user_psize, 0);
  467. }
  468. unsigned long arch_get_unmapped_area_topdown(struct file *filp,
  469. const unsigned long addr0,
  470. const unsigned long len,
  471. const unsigned long pgoff,
  472. const unsigned long flags)
  473. {
  474. return slice_get_unmapped_area(addr0, len, flags,
  475. current->mm->context.user_psize, 1);
  476. }
  477. unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr)
  478. {
  479. unsigned char *hpsizes;
  480. int index, mask_index;
  481. if (addr < SLICE_LOW_TOP) {
  482. u64 lpsizes;
  483. lpsizes = mm->context.low_slices_psize;
  484. index = GET_LOW_SLICE_INDEX(addr);
  485. return (lpsizes >> (index * 4)) & 0xf;
  486. }
  487. hpsizes = mm->context.high_slices_psize;
  488. index = GET_HIGH_SLICE_INDEX(addr);
  489. mask_index = index & 0x1;
  490. return (hpsizes[index >> 1] >> (mask_index * 4)) & 0xf;
  491. }
  492. EXPORT_SYMBOL_GPL(get_slice_psize);
  493. /*
  494. * This is called by hash_page when it needs to do a lazy conversion of
  495. * an address space from real 64K pages to combo 4K pages (typically
  496. * when hitting a non cacheable mapping on a processor or hypervisor
  497. * that won't allow them for 64K pages).
  498. *
  499. * This is also called in init_new_context() to change back the user
  500. * psize from whatever the parent context had it set to
  501. * N.B. This may be called before mm->context.id has been set.
  502. *
  503. * This function will only change the content of the {low,high)_slice_psize
  504. * masks, it will not flush SLBs as this shall be handled lazily by the
  505. * caller.
  506. */
  507. void slice_set_user_psize(struct mm_struct *mm, unsigned int psize)
  508. {
  509. int index, mask_index;
  510. unsigned char *hpsizes;
  511. unsigned long flags, lpsizes;
  512. unsigned int old_psize;
  513. int i;
  514. slice_dbg("slice_set_user_psize(mm=%p, psize=%d)\n", mm, psize);
  515. spin_lock_irqsave(&slice_convert_lock, flags);
  516. old_psize = mm->context.user_psize;
  517. slice_dbg(" old_psize=%d\n", old_psize);
  518. if (old_psize == psize)
  519. goto bail;
  520. mm->context.user_psize = psize;
  521. wmb();
  522. lpsizes = mm->context.low_slices_psize;
  523. for (i = 0; i < SLICE_NUM_LOW; i++)
  524. if (((lpsizes >> (i * 4)) & 0xf) == old_psize)
  525. lpsizes = (lpsizes & ~(0xful << (i * 4))) |
  526. (((unsigned long)psize) << (i * 4));
  527. /* Assign the value back */
  528. mm->context.low_slices_psize = lpsizes;
  529. hpsizes = mm->context.high_slices_psize;
  530. for (i = 0; i < SLICE_NUM_HIGH; i++) {
  531. mask_index = i & 0x1;
  532. index = i >> 1;
  533. if (((hpsizes[index] >> (mask_index * 4)) & 0xf) == old_psize)
  534. hpsizes[index] = (hpsizes[index] &
  535. ~(0xf << (mask_index * 4))) |
  536. (((unsigned long)psize) << (mask_index * 4));
  537. }
  538. slice_dbg(" lsps=%lx, hsps=%lx\n",
  539. mm->context.low_slices_psize,
  540. mm->context.high_slices_psize);
  541. bail:
  542. spin_unlock_irqrestore(&slice_convert_lock, flags);
  543. }
  544. void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
  545. unsigned long len, unsigned int psize)
  546. {
  547. struct slice_mask mask = slice_range_to_mask(start, len);
  548. slice_convert(mm, mask, psize);
  549. }
  550. #ifdef CONFIG_HUGETLB_PAGE
  551. /*
  552. * is_hugepage_only_range() is used by generic code to verify whether
  553. * a normal mmap mapping (non hugetlbfs) is valid on a given area.
  554. *
  555. * until the generic code provides a more generic hook and/or starts
  556. * calling arch get_unmapped_area for MAP_FIXED (which our implementation
  557. * here knows how to deal with), we hijack it to keep standard mappings
  558. * away from us.
  559. *
  560. * because of that generic code limitation, MAP_FIXED mapping cannot
  561. * "convert" back a slice with no VMAs to the standard page size, only
  562. * get_unmapped_area() can. It would be possible to fix it here but I
  563. * prefer working on fixing the generic code instead.
  564. *
  565. * WARNING: This will not work if hugetlbfs isn't enabled since the
  566. * generic code will redefine that function as 0 in that. This is ok
  567. * for now as we only use slices with hugetlbfs enabled. This should
  568. * be fixed as the generic code gets fixed.
  569. */
  570. int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
  571. unsigned long len)
  572. {
  573. struct slice_mask mask, available;
  574. unsigned int psize = mm->context.user_psize;
  575. mask = slice_range_to_mask(addr, len);
  576. available = slice_mask_for_size(mm, psize);
  577. #ifdef CONFIG_PPC_64K_PAGES
  578. /* We need to account for 4k slices too */
  579. if (psize == MMU_PAGE_64K) {
  580. struct slice_mask compat_mask;
  581. compat_mask = slice_mask_for_size(mm, MMU_PAGE_4K);
  582. or_mask(available, compat_mask);
  583. }
  584. #endif
  585. #if 0 /* too verbose */
  586. slice_dbg("is_hugepage_only_range(mm=%p, addr=%lx, len=%lx)\n",
  587. mm, addr, len);
  588. slice_print_mask(" mask", mask);
  589. slice_print_mask(" available", available);
  590. #endif
  591. return !slice_check_fit(mask, available);
  592. }
  593. #endif