hash_utils_64.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. /*
  2. * PowerPC64 port by Mike Corrigan and Dave Engebretsen
  3. * {mikejc|engebret}@us.ibm.com
  4. *
  5. * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com>
  6. *
  7. * SMP scalability work:
  8. * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
  9. *
  10. * Module name: htab.c
  11. *
  12. * Description:
  13. * PowerPC Hashed Page Table functions
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #undef DEBUG
  21. #undef DEBUG_LOW
  22. #include <linux/spinlock.h>
  23. #include <linux/errno.h>
  24. #include <linux/sched.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/stat.h>
  27. #include <linux/sysctl.h>
  28. #include <linux/export.h>
  29. #include <linux/ctype.h>
  30. #include <linux/cache.h>
  31. #include <linux/init.h>
  32. #include <linux/signal.h>
  33. #include <linux/memblock.h>
  34. #include <linux/context_tracking.h>
  35. #include <linux/libfdt.h>
  36. #include <asm/processor.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/mmu.h>
  39. #include <asm/mmu_context.h>
  40. #include <asm/page.h>
  41. #include <asm/types.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/machdep.h>
  44. #include <asm/prom.h>
  45. #include <asm/tlbflush.h>
  46. #include <asm/io.h>
  47. #include <asm/eeh.h>
  48. #include <asm/tlb.h>
  49. #include <asm/cacheflush.h>
  50. #include <asm/cputable.h>
  51. #include <asm/sections.h>
  52. #include <asm/copro.h>
  53. #include <asm/udbg.h>
  54. #include <asm/code-patching.h>
  55. #include <asm/fadump.h>
  56. #include <asm/firmware.h>
  57. #include <asm/tm.h>
  58. #include <asm/trace.h>
  59. #include <asm/ps3.h>
  60. #ifdef DEBUG
  61. #define DBG(fmt...) udbg_printf(fmt)
  62. #else
  63. #define DBG(fmt...)
  64. #endif
  65. #ifdef DEBUG_LOW
  66. #define DBG_LOW(fmt...) udbg_printf(fmt)
  67. #else
  68. #define DBG_LOW(fmt...)
  69. #endif
  70. #define KB (1024)
  71. #define MB (1024*KB)
  72. #define GB (1024L*MB)
  73. /*
  74. * Note: pte --> Linux PTE
  75. * HPTE --> PowerPC Hashed Page Table Entry
  76. *
  77. * Execution context:
  78. * htab_initialize is called with the MMU off (of course), but
  79. * the kernel has been copied down to zero so it can directly
  80. * reference global data. At this point it is very difficult
  81. * to print debug info.
  82. *
  83. */
  84. static unsigned long _SDR1;
  85. struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
  86. EXPORT_SYMBOL_GPL(mmu_psize_defs);
  87. struct hash_pte *htab_address;
  88. unsigned long htab_size_bytes;
  89. unsigned long htab_hash_mask;
  90. EXPORT_SYMBOL_GPL(htab_hash_mask);
  91. int mmu_linear_psize = MMU_PAGE_4K;
  92. EXPORT_SYMBOL_GPL(mmu_linear_psize);
  93. int mmu_virtual_psize = MMU_PAGE_4K;
  94. int mmu_vmalloc_psize = MMU_PAGE_4K;
  95. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  96. int mmu_vmemmap_psize = MMU_PAGE_4K;
  97. #endif
  98. int mmu_io_psize = MMU_PAGE_4K;
  99. int mmu_kernel_ssize = MMU_SEGSIZE_256M;
  100. EXPORT_SYMBOL_GPL(mmu_kernel_ssize);
  101. int mmu_highuser_ssize = MMU_SEGSIZE_256M;
  102. u16 mmu_slb_size = 64;
  103. EXPORT_SYMBOL_GPL(mmu_slb_size);
  104. #ifdef CONFIG_PPC_64K_PAGES
  105. int mmu_ci_restrictions;
  106. #endif
  107. #ifdef CONFIG_DEBUG_PAGEALLOC
  108. static u8 *linear_map_hash_slots;
  109. static unsigned long linear_map_hash_count;
  110. static DEFINE_SPINLOCK(linear_map_hash_lock);
  111. #endif /* CONFIG_DEBUG_PAGEALLOC */
  112. struct mmu_hash_ops mmu_hash_ops;
  113. EXPORT_SYMBOL(mmu_hash_ops);
  114. /* There are definitions of page sizes arrays to be used when none
  115. * is provided by the firmware.
  116. */
  117. /* Pre-POWER4 CPUs (4k pages only)
  118. */
  119. static struct mmu_psize_def mmu_psize_defaults_old[] = {
  120. [MMU_PAGE_4K] = {
  121. .shift = 12,
  122. .sllp = 0,
  123. .penc = {[MMU_PAGE_4K] = 0, [1 ... MMU_PAGE_COUNT - 1] = -1},
  124. .avpnm = 0,
  125. .tlbiel = 0,
  126. },
  127. };
  128. /* POWER4, GPUL, POWER5
  129. *
  130. * Support for 16Mb large pages
  131. */
  132. static struct mmu_psize_def mmu_psize_defaults_gp[] = {
  133. [MMU_PAGE_4K] = {
  134. .shift = 12,
  135. .sllp = 0,
  136. .penc = {[MMU_PAGE_4K] = 0, [1 ... MMU_PAGE_COUNT - 1] = -1},
  137. .avpnm = 0,
  138. .tlbiel = 1,
  139. },
  140. [MMU_PAGE_16M] = {
  141. .shift = 24,
  142. .sllp = SLB_VSID_L,
  143. .penc = {[0 ... MMU_PAGE_16M - 1] = -1, [MMU_PAGE_16M] = 0,
  144. [MMU_PAGE_16M + 1 ... MMU_PAGE_COUNT - 1] = -1 },
  145. .avpnm = 0x1UL,
  146. .tlbiel = 0,
  147. },
  148. };
  149. /*
  150. * 'R' and 'C' update notes:
  151. * - Under pHyp or KVM, the updatepp path will not set C, thus it *will*
  152. * create writeable HPTEs without C set, because the hcall H_PROTECT
  153. * that we use in that case will not update C
  154. * - The above is however not a problem, because we also don't do that
  155. * fancy "no flush" variant of eviction and we use H_REMOVE which will
  156. * do the right thing and thus we don't have the race I described earlier
  157. *
  158. * - Under bare metal, we do have the race, so we need R and C set
  159. * - We make sure R is always set and never lost
  160. * - C is _PAGE_DIRTY, and *should* always be set for a writeable mapping
  161. */
  162. unsigned long htab_convert_pte_flags(unsigned long pteflags)
  163. {
  164. unsigned long rflags = 0;
  165. /* _PAGE_EXEC -> NOEXEC */
  166. if ((pteflags & _PAGE_EXEC) == 0)
  167. rflags |= HPTE_R_N;
  168. /*
  169. * PPP bits:
  170. * Linux uses slb key 0 for kernel and 1 for user.
  171. * kernel RW areas are mapped with PPP=0b000
  172. * User area is mapped with PPP=0b010 for read/write
  173. * or PPP=0b011 for read-only (including writeable but clean pages).
  174. */
  175. if (pteflags & _PAGE_PRIVILEGED) {
  176. /*
  177. * Kernel read only mapped with ppp bits 0b110
  178. */
  179. if (!(pteflags & _PAGE_WRITE))
  180. rflags |= (HPTE_R_PP0 | 0x2);
  181. } else {
  182. if (pteflags & _PAGE_RWX)
  183. rflags |= 0x2;
  184. if (!((pteflags & _PAGE_WRITE) && (pteflags & _PAGE_DIRTY)))
  185. rflags |= 0x1;
  186. }
  187. /*
  188. * We can't allow hardware to update hpte bits. Hence always
  189. * set 'R' bit and set 'C' if it is a write fault
  190. */
  191. rflags |= HPTE_R_R;
  192. if (pteflags & _PAGE_DIRTY)
  193. rflags |= HPTE_R_C;
  194. /*
  195. * Add in WIG bits
  196. */
  197. if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_TOLERANT)
  198. rflags |= HPTE_R_I;
  199. else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)
  200. rflags |= (HPTE_R_I | HPTE_R_G);
  201. else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
  202. rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);
  203. else
  204. /*
  205. * Add memory coherence if cache inhibited is not set
  206. */
  207. rflags |= HPTE_R_M;
  208. return rflags;
  209. }
  210. int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
  211. unsigned long pstart, unsigned long prot,
  212. int psize, int ssize)
  213. {
  214. unsigned long vaddr, paddr;
  215. unsigned int step, shift;
  216. int ret = 0;
  217. shift = mmu_psize_defs[psize].shift;
  218. step = 1 << shift;
  219. prot = htab_convert_pte_flags(prot);
  220. DBG("htab_bolt_mapping(%lx..%lx -> %lx (%lx,%d,%d)\n",
  221. vstart, vend, pstart, prot, psize, ssize);
  222. for (vaddr = vstart, paddr = pstart; vaddr < vend;
  223. vaddr += step, paddr += step) {
  224. unsigned long hash, hpteg;
  225. unsigned long vsid = get_kernel_vsid(vaddr, ssize);
  226. unsigned long vpn = hpt_vpn(vaddr, vsid, ssize);
  227. unsigned long tprot = prot;
  228. /*
  229. * If we hit a bad address return error.
  230. */
  231. if (!vsid)
  232. return -1;
  233. /* Make kernel text executable */
  234. if (overlaps_kernel_text(vaddr, vaddr + step))
  235. tprot &= ~HPTE_R_N;
  236. /* Make kvm guest trampolines executable */
  237. if (overlaps_kvm_tmp(vaddr, vaddr + step))
  238. tprot &= ~HPTE_R_N;
  239. /*
  240. * If relocatable, check if it overlaps interrupt vectors that
  241. * are copied down to real 0. For relocatable kernel
  242. * (e.g. kdump case) we copy interrupt vectors down to real
  243. * address 0. Mark that region as executable. This is
  244. * because on p8 system with relocation on exception feature
  245. * enabled, exceptions are raised with MMU (IR=DR=1) ON. Hence
  246. * in order to execute the interrupt handlers in virtual
  247. * mode the vector region need to be marked as executable.
  248. */
  249. if ((PHYSICAL_START > MEMORY_START) &&
  250. overlaps_interrupt_vector_text(vaddr, vaddr + step))
  251. tprot &= ~HPTE_R_N;
  252. hash = hpt_hash(vpn, shift, ssize);
  253. hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
  254. BUG_ON(!mmu_hash_ops.hpte_insert);
  255. ret = mmu_hash_ops.hpte_insert(hpteg, vpn, paddr, tprot,
  256. HPTE_V_BOLTED, psize, psize,
  257. ssize);
  258. if (ret < 0)
  259. break;
  260. #ifdef CONFIG_DEBUG_PAGEALLOC
  261. if (debug_pagealloc_enabled() &&
  262. (paddr >> PAGE_SHIFT) < linear_map_hash_count)
  263. linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80;
  264. #endif /* CONFIG_DEBUG_PAGEALLOC */
  265. }
  266. return ret < 0 ? ret : 0;
  267. }
  268. int htab_remove_mapping(unsigned long vstart, unsigned long vend,
  269. int psize, int ssize)
  270. {
  271. unsigned long vaddr;
  272. unsigned int step, shift;
  273. int rc;
  274. int ret = 0;
  275. shift = mmu_psize_defs[psize].shift;
  276. step = 1 << shift;
  277. if (!mmu_hash_ops.hpte_removebolted)
  278. return -ENODEV;
  279. for (vaddr = vstart; vaddr < vend; vaddr += step) {
  280. rc = mmu_hash_ops.hpte_removebolted(vaddr, psize, ssize);
  281. if (rc == -ENOENT) {
  282. ret = -ENOENT;
  283. continue;
  284. }
  285. if (rc < 0)
  286. return rc;
  287. }
  288. return ret;
  289. }
  290. static bool disable_1tb_segments = false;
  291. static int __init parse_disable_1tb_segments(char *p)
  292. {
  293. disable_1tb_segments = true;
  294. return 0;
  295. }
  296. early_param("disable_1tb_segments", parse_disable_1tb_segments);
  297. static int __init htab_dt_scan_seg_sizes(unsigned long node,
  298. const char *uname, int depth,
  299. void *data)
  300. {
  301. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  302. const __be32 *prop;
  303. int size = 0;
  304. /* We are scanning "cpu" nodes only */
  305. if (type == NULL || strcmp(type, "cpu") != 0)
  306. return 0;
  307. prop = of_get_flat_dt_prop(node, "ibm,processor-segment-sizes", &size);
  308. if (prop == NULL)
  309. return 0;
  310. for (; size >= 4; size -= 4, ++prop) {
  311. if (be32_to_cpu(prop[0]) == 40) {
  312. DBG("1T segment support detected\n");
  313. if (disable_1tb_segments) {
  314. DBG("1T segments disabled by command line\n");
  315. break;
  316. }
  317. cur_cpu_spec->mmu_features |= MMU_FTR_1T_SEGMENT;
  318. return 1;
  319. }
  320. }
  321. cur_cpu_spec->mmu_features &= ~MMU_FTR_NO_SLBIE_B;
  322. return 0;
  323. }
  324. static int __init get_idx_from_shift(unsigned int shift)
  325. {
  326. int idx = -1;
  327. switch (shift) {
  328. case 0xc:
  329. idx = MMU_PAGE_4K;
  330. break;
  331. case 0x10:
  332. idx = MMU_PAGE_64K;
  333. break;
  334. case 0x14:
  335. idx = MMU_PAGE_1M;
  336. break;
  337. case 0x18:
  338. idx = MMU_PAGE_16M;
  339. break;
  340. case 0x22:
  341. idx = MMU_PAGE_16G;
  342. break;
  343. }
  344. return idx;
  345. }
  346. static int __init htab_dt_scan_page_sizes(unsigned long node,
  347. const char *uname, int depth,
  348. void *data)
  349. {
  350. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  351. const __be32 *prop;
  352. int size = 0;
  353. /* We are scanning "cpu" nodes only */
  354. if (type == NULL || strcmp(type, "cpu") != 0)
  355. return 0;
  356. prop = of_get_flat_dt_prop(node, "ibm,segment-page-sizes", &size);
  357. if (!prop)
  358. return 0;
  359. pr_info("Page sizes from device-tree:\n");
  360. size /= 4;
  361. cur_cpu_spec->mmu_features &= ~(MMU_FTR_16M_PAGE);
  362. while(size > 0) {
  363. unsigned int base_shift = be32_to_cpu(prop[0]);
  364. unsigned int slbenc = be32_to_cpu(prop[1]);
  365. unsigned int lpnum = be32_to_cpu(prop[2]);
  366. struct mmu_psize_def *def;
  367. int idx, base_idx;
  368. size -= 3; prop += 3;
  369. base_idx = get_idx_from_shift(base_shift);
  370. if (base_idx < 0) {
  371. /* skip the pte encoding also */
  372. prop += lpnum * 2; size -= lpnum * 2;
  373. continue;
  374. }
  375. def = &mmu_psize_defs[base_idx];
  376. if (base_idx == MMU_PAGE_16M)
  377. cur_cpu_spec->mmu_features |= MMU_FTR_16M_PAGE;
  378. def->shift = base_shift;
  379. if (base_shift <= 23)
  380. def->avpnm = 0;
  381. else
  382. def->avpnm = (1 << (base_shift - 23)) - 1;
  383. def->sllp = slbenc;
  384. /*
  385. * We don't know for sure what's up with tlbiel, so
  386. * for now we only set it for 4K and 64K pages
  387. */
  388. if (base_idx == MMU_PAGE_4K || base_idx == MMU_PAGE_64K)
  389. def->tlbiel = 1;
  390. else
  391. def->tlbiel = 0;
  392. while (size > 0 && lpnum) {
  393. unsigned int shift = be32_to_cpu(prop[0]);
  394. int penc = be32_to_cpu(prop[1]);
  395. prop += 2; size -= 2;
  396. lpnum--;
  397. idx = get_idx_from_shift(shift);
  398. if (idx < 0)
  399. continue;
  400. if (penc == -1)
  401. pr_err("Invalid penc for base_shift=%d "
  402. "shift=%d\n", base_shift, shift);
  403. def->penc[idx] = penc;
  404. pr_info("base_shift=%d: shift=%d, sllp=0x%04lx,"
  405. " avpnm=0x%08lx, tlbiel=%d, penc=%d\n",
  406. base_shift, shift, def->sllp,
  407. def->avpnm, def->tlbiel, def->penc[idx]);
  408. }
  409. }
  410. return 1;
  411. }
  412. #ifdef CONFIG_HUGETLB_PAGE
  413. /* Scan for 16G memory blocks that have been set aside for huge pages
  414. * and reserve those blocks for 16G huge pages.
  415. */
  416. static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
  417. const char *uname, int depth,
  418. void *data) {
  419. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  420. const __be64 *addr_prop;
  421. const __be32 *page_count_prop;
  422. unsigned int expected_pages;
  423. long unsigned int phys_addr;
  424. long unsigned int block_size;
  425. /* We are scanning "memory" nodes only */
  426. if (type == NULL || strcmp(type, "memory") != 0)
  427. return 0;
  428. /* This property is the log base 2 of the number of virtual pages that
  429. * will represent this memory block. */
  430. page_count_prop = of_get_flat_dt_prop(node, "ibm,expected#pages", NULL);
  431. if (page_count_prop == NULL)
  432. return 0;
  433. expected_pages = (1 << be32_to_cpu(page_count_prop[0]));
  434. addr_prop = of_get_flat_dt_prop(node, "reg", NULL);
  435. if (addr_prop == NULL)
  436. return 0;
  437. phys_addr = be64_to_cpu(addr_prop[0]);
  438. block_size = be64_to_cpu(addr_prop[1]);
  439. if (block_size != (16 * GB))
  440. return 0;
  441. printk(KERN_INFO "Huge page(16GB) memory: "
  442. "addr = 0x%lX size = 0x%lX pages = %d\n",
  443. phys_addr, block_size, expected_pages);
  444. if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
  445. memblock_reserve(phys_addr, block_size * expected_pages);
  446. add_gpage(phys_addr, block_size, expected_pages);
  447. }
  448. return 0;
  449. }
  450. #endif /* CONFIG_HUGETLB_PAGE */
  451. static void mmu_psize_set_default_penc(void)
  452. {
  453. int bpsize, apsize;
  454. for (bpsize = 0; bpsize < MMU_PAGE_COUNT; bpsize++)
  455. for (apsize = 0; apsize < MMU_PAGE_COUNT; apsize++)
  456. mmu_psize_defs[bpsize].penc[apsize] = -1;
  457. }
  458. #ifdef CONFIG_PPC_64K_PAGES
  459. static bool might_have_hea(void)
  460. {
  461. /*
  462. * The HEA ethernet adapter requires awareness of the
  463. * GX bus. Without that awareness we can easily assume
  464. * we will never see an HEA ethernet device.
  465. */
  466. #ifdef CONFIG_IBMEBUS
  467. return !cpu_has_feature(CPU_FTR_ARCH_207S) &&
  468. !firmware_has_feature(FW_FEATURE_SPLPAR);
  469. #else
  470. return false;
  471. #endif
  472. }
  473. #endif /* #ifdef CONFIG_PPC_64K_PAGES */
  474. static void __init htab_scan_page_sizes(void)
  475. {
  476. int rc;
  477. /* se the invalid penc to -1 */
  478. mmu_psize_set_default_penc();
  479. /* Default to 4K pages only */
  480. memcpy(mmu_psize_defs, mmu_psize_defaults_old,
  481. sizeof(mmu_psize_defaults_old));
  482. /*
  483. * Try to find the available page sizes in the device-tree
  484. */
  485. rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL);
  486. if (rc == 0 && early_mmu_has_feature(MMU_FTR_16M_PAGE)) {
  487. /*
  488. * Nothing in the device-tree, but the CPU supports 16M pages,
  489. * so let's fallback on a known size list for 16M capable CPUs.
  490. */
  491. memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
  492. sizeof(mmu_psize_defaults_gp));
  493. }
  494. #ifdef CONFIG_HUGETLB_PAGE
  495. /* Reserve 16G huge page memory sections for huge pages */
  496. of_scan_flat_dt(htab_dt_scan_hugepage_blocks, NULL);
  497. #endif /* CONFIG_HUGETLB_PAGE */
  498. }
  499. static void __init htab_init_page_sizes(void)
  500. {
  501. if (!debug_pagealloc_enabled()) {
  502. /*
  503. * Pick a size for the linear mapping. Currently, we only
  504. * support 16M, 1M and 4K which is the default
  505. */
  506. if (mmu_psize_defs[MMU_PAGE_16M].shift)
  507. mmu_linear_psize = MMU_PAGE_16M;
  508. else if (mmu_psize_defs[MMU_PAGE_1M].shift)
  509. mmu_linear_psize = MMU_PAGE_1M;
  510. }
  511. #ifdef CONFIG_PPC_64K_PAGES
  512. /*
  513. * Pick a size for the ordinary pages. Default is 4K, we support
  514. * 64K for user mappings and vmalloc if supported by the processor.
  515. * We only use 64k for ioremap if the processor
  516. * (and firmware) support cache-inhibited large pages.
  517. * If not, we use 4k and set mmu_ci_restrictions so that
  518. * hash_page knows to switch processes that use cache-inhibited
  519. * mappings to 4k pages.
  520. */
  521. if (mmu_psize_defs[MMU_PAGE_64K].shift) {
  522. mmu_virtual_psize = MMU_PAGE_64K;
  523. mmu_vmalloc_psize = MMU_PAGE_64K;
  524. if (mmu_linear_psize == MMU_PAGE_4K)
  525. mmu_linear_psize = MMU_PAGE_64K;
  526. if (mmu_has_feature(MMU_FTR_CI_LARGE_PAGE)) {
  527. /*
  528. * When running on pSeries using 64k pages for ioremap
  529. * would stop us accessing the HEA ethernet. So if we
  530. * have the chance of ever seeing one, stay at 4k.
  531. */
  532. if (!might_have_hea())
  533. mmu_io_psize = MMU_PAGE_64K;
  534. } else
  535. mmu_ci_restrictions = 1;
  536. }
  537. #endif /* CONFIG_PPC_64K_PAGES */
  538. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  539. /* We try to use 16M pages for vmemmap if that is supported
  540. * and we have at least 1G of RAM at boot
  541. */
  542. if (mmu_psize_defs[MMU_PAGE_16M].shift &&
  543. memblock_phys_mem_size() >= 0x40000000)
  544. mmu_vmemmap_psize = MMU_PAGE_16M;
  545. else if (mmu_psize_defs[MMU_PAGE_64K].shift)
  546. mmu_vmemmap_psize = MMU_PAGE_64K;
  547. else
  548. mmu_vmemmap_psize = MMU_PAGE_4K;
  549. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  550. printk(KERN_DEBUG "Page orders: linear mapping = %d, "
  551. "virtual = %d, io = %d"
  552. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  553. ", vmemmap = %d"
  554. #endif
  555. "\n",
  556. mmu_psize_defs[mmu_linear_psize].shift,
  557. mmu_psize_defs[mmu_virtual_psize].shift,
  558. mmu_psize_defs[mmu_io_psize].shift
  559. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  560. ,mmu_psize_defs[mmu_vmemmap_psize].shift
  561. #endif
  562. );
  563. }
  564. static int __init htab_dt_scan_pftsize(unsigned long node,
  565. const char *uname, int depth,
  566. void *data)
  567. {
  568. const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
  569. const __be32 *prop;
  570. /* We are scanning "cpu" nodes only */
  571. if (type == NULL || strcmp(type, "cpu") != 0)
  572. return 0;
  573. prop = of_get_flat_dt_prop(node, "ibm,pft-size", NULL);
  574. if (prop != NULL) {
  575. /* pft_size[0] is the NUMA CEC cookie */
  576. ppc64_pft_size = be32_to_cpu(prop[1]);
  577. return 1;
  578. }
  579. return 0;
  580. }
  581. unsigned htab_shift_for_mem_size(unsigned long mem_size)
  582. {
  583. unsigned memshift = __ilog2(mem_size);
  584. unsigned pshift = mmu_psize_defs[mmu_virtual_psize].shift;
  585. unsigned pteg_shift;
  586. /* round mem_size up to next power of 2 */
  587. if ((1UL << memshift) < mem_size)
  588. memshift += 1;
  589. /* aim for 2 pages / pteg */
  590. pteg_shift = memshift - (pshift + 1);
  591. /*
  592. * 2^11 PTEGS of 128 bytes each, ie. 2^18 bytes is the minimum htab
  593. * size permitted by the architecture.
  594. */
  595. return max(pteg_shift + 7, 18U);
  596. }
  597. static unsigned long __init htab_get_table_size(void)
  598. {
  599. /* If hash size isn't already provided by the platform, we try to
  600. * retrieve it from the device-tree. If it's not there neither, we
  601. * calculate it now based on the total RAM size
  602. */
  603. if (ppc64_pft_size == 0)
  604. of_scan_flat_dt(htab_dt_scan_pftsize, NULL);
  605. if (ppc64_pft_size)
  606. return 1UL << ppc64_pft_size;
  607. return 1UL << htab_shift_for_mem_size(memblock_phys_mem_size());
  608. }
  609. #ifdef CONFIG_MEMORY_HOTPLUG
  610. int create_section_mapping(unsigned long start, unsigned long end)
  611. {
  612. int rc = htab_bolt_mapping(start, end, __pa(start),
  613. pgprot_val(PAGE_KERNEL), mmu_linear_psize,
  614. mmu_kernel_ssize);
  615. if (rc < 0) {
  616. int rc2 = htab_remove_mapping(start, end, mmu_linear_psize,
  617. mmu_kernel_ssize);
  618. BUG_ON(rc2 && (rc2 != -ENOENT));
  619. }
  620. return rc;
  621. }
  622. int remove_section_mapping(unsigned long start, unsigned long end)
  623. {
  624. int rc = htab_remove_mapping(start, end, mmu_linear_psize,
  625. mmu_kernel_ssize);
  626. WARN_ON(rc < 0);
  627. return rc;
  628. }
  629. #endif /* CONFIG_MEMORY_HOTPLUG */
  630. static void __init hash_init_partition_table(phys_addr_t hash_table,
  631. unsigned long htab_size)
  632. {
  633. unsigned long ps_field;
  634. unsigned long patb_size = 1UL << PATB_SIZE_SHIFT;
  635. /*
  636. * slb llp encoding for the page size used in VPM real mode.
  637. * We can ignore that for lpid 0
  638. */
  639. ps_field = 0;
  640. htab_size = __ilog2(htab_size) - 18;
  641. BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 24), "Partition table size too large.");
  642. partition_tb = __va(memblock_alloc_base(patb_size, patb_size,
  643. MEMBLOCK_ALLOC_ANYWHERE));
  644. /* Initialize the Partition Table with no entries */
  645. memset((void *)partition_tb, 0, patb_size);
  646. partition_tb->patb0 = cpu_to_be64(ps_field | hash_table | htab_size);
  647. /*
  648. * FIXME!! This should be done via update_partition table
  649. * For now UPRT is 0 for us.
  650. */
  651. partition_tb->patb1 = 0;
  652. pr_info("Partition table %p\n", partition_tb);
  653. /*
  654. * update partition table control register,
  655. * 64 K size.
  656. */
  657. mtspr(SPRN_PTCR, __pa(partition_tb) | (PATB_SIZE_SHIFT - 12));
  658. }
  659. static void __init htab_initialize(void)
  660. {
  661. unsigned long table;
  662. unsigned long pteg_count;
  663. unsigned long prot;
  664. unsigned long base = 0, size = 0;
  665. struct memblock_region *reg;
  666. DBG(" -> htab_initialize()\n");
  667. if (mmu_has_feature(MMU_FTR_1T_SEGMENT)) {
  668. mmu_kernel_ssize = MMU_SEGSIZE_1T;
  669. mmu_highuser_ssize = MMU_SEGSIZE_1T;
  670. printk(KERN_INFO "Using 1TB segments\n");
  671. }
  672. /*
  673. * Calculate the required size of the htab. We want the number of
  674. * PTEGs to equal one half the number of real pages.
  675. */
  676. htab_size_bytes = htab_get_table_size();
  677. pteg_count = htab_size_bytes >> 7;
  678. htab_hash_mask = pteg_count - 1;
  679. if (firmware_has_feature(FW_FEATURE_LPAR) ||
  680. firmware_has_feature(FW_FEATURE_PS3_LV1)) {
  681. /* Using a hypervisor which owns the htab */
  682. htab_address = NULL;
  683. _SDR1 = 0;
  684. #ifdef CONFIG_FA_DUMP
  685. /*
  686. * If firmware assisted dump is active firmware preserves
  687. * the contents of htab along with entire partition memory.
  688. * Clear the htab if firmware assisted dump is active so
  689. * that we dont end up using old mappings.
  690. */
  691. if (is_fadump_active() && mmu_hash_ops.hpte_clear_all)
  692. mmu_hash_ops.hpte_clear_all();
  693. #endif
  694. } else {
  695. unsigned long limit = MEMBLOCK_ALLOC_ANYWHERE;
  696. #ifdef CONFIG_PPC_CELL
  697. /*
  698. * Cell may require the hash table down low when using the
  699. * Axon IOMMU in order to fit the dynamic region over it, see
  700. * comments in cell/iommu.c
  701. */
  702. if (fdt_subnode_offset(initial_boot_params, 0, "axon") > 0) {
  703. limit = 0x80000000;
  704. pr_info("Hash table forced below 2G for Axon IOMMU\n");
  705. }
  706. #endif /* CONFIG_PPC_CELL */
  707. table = memblock_alloc_base(htab_size_bytes, htab_size_bytes,
  708. limit);
  709. DBG("Hash table allocated at %lx, size: %lx\n", table,
  710. htab_size_bytes);
  711. htab_address = __va(table);
  712. /* htab absolute addr + encoded htabsize */
  713. _SDR1 = table + __ilog2(htab_size_bytes) - 18;
  714. /* Initialize the HPT with no entries */
  715. memset((void *)table, 0, htab_size_bytes);
  716. if (!cpu_has_feature(CPU_FTR_ARCH_300))
  717. /* Set SDR1 */
  718. mtspr(SPRN_SDR1, _SDR1);
  719. else
  720. hash_init_partition_table(table, htab_size_bytes);
  721. }
  722. prot = pgprot_val(PAGE_KERNEL);
  723. #ifdef CONFIG_DEBUG_PAGEALLOC
  724. if (debug_pagealloc_enabled()) {
  725. linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
  726. linear_map_hash_slots = __va(memblock_alloc_base(
  727. linear_map_hash_count, 1, ppc64_rma_size));
  728. memset(linear_map_hash_slots, 0, linear_map_hash_count);
  729. }
  730. #endif /* CONFIG_DEBUG_PAGEALLOC */
  731. /* On U3 based machines, we need to reserve the DART area and
  732. * _NOT_ map it to avoid cache paradoxes as it's remapped non
  733. * cacheable later on
  734. */
  735. /* create bolted the linear mapping in the hash table */
  736. for_each_memblock(memory, reg) {
  737. base = (unsigned long)__va(reg->base);
  738. size = reg->size;
  739. DBG("creating mapping for region: %lx..%lx (prot: %lx)\n",
  740. base, size, prot);
  741. BUG_ON(htab_bolt_mapping(base, base + size, __pa(base),
  742. prot, mmu_linear_psize, mmu_kernel_ssize));
  743. }
  744. memblock_set_current_limit(MEMBLOCK_ALLOC_ANYWHERE);
  745. /*
  746. * If we have a memory_limit and we've allocated TCEs then we need to
  747. * explicitly map the TCE area at the top of RAM. We also cope with the
  748. * case that the TCEs start below memory_limit.
  749. * tce_alloc_start/end are 16MB aligned so the mapping should work
  750. * for either 4K or 16MB pages.
  751. */
  752. if (tce_alloc_start) {
  753. tce_alloc_start = (unsigned long)__va(tce_alloc_start);
  754. tce_alloc_end = (unsigned long)__va(tce_alloc_end);
  755. if (base + size >= tce_alloc_start)
  756. tce_alloc_start = base + size + 1;
  757. BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end,
  758. __pa(tce_alloc_start), prot,
  759. mmu_linear_psize, mmu_kernel_ssize));
  760. }
  761. DBG(" <- htab_initialize()\n");
  762. }
  763. #undef KB
  764. #undef MB
  765. void __init hash__early_init_devtree(void)
  766. {
  767. /* Initialize segment sizes */
  768. of_scan_flat_dt(htab_dt_scan_seg_sizes, NULL);
  769. /* Initialize page sizes */
  770. htab_scan_page_sizes();
  771. }
  772. void __init hash__early_init_mmu(void)
  773. {
  774. htab_init_page_sizes();
  775. /*
  776. * initialize page table size
  777. */
  778. __pte_frag_nr = H_PTE_FRAG_NR;
  779. __pte_frag_size_shift = H_PTE_FRAG_SIZE_SHIFT;
  780. __pte_index_size = H_PTE_INDEX_SIZE;
  781. __pmd_index_size = H_PMD_INDEX_SIZE;
  782. __pud_index_size = H_PUD_INDEX_SIZE;
  783. __pgd_index_size = H_PGD_INDEX_SIZE;
  784. __pmd_cache_index = H_PMD_CACHE_INDEX;
  785. __pte_table_size = H_PTE_TABLE_SIZE;
  786. __pmd_table_size = H_PMD_TABLE_SIZE;
  787. __pud_table_size = H_PUD_TABLE_SIZE;
  788. __pgd_table_size = H_PGD_TABLE_SIZE;
  789. /*
  790. * 4k use hugepd format, so for hash set then to
  791. * zero
  792. */
  793. __pmd_val_bits = 0;
  794. __pud_val_bits = 0;
  795. __pgd_val_bits = 0;
  796. __kernel_virt_start = H_KERN_VIRT_START;
  797. __kernel_virt_size = H_KERN_VIRT_SIZE;
  798. __vmalloc_start = H_VMALLOC_START;
  799. __vmalloc_end = H_VMALLOC_END;
  800. vmemmap = (struct page *)H_VMEMMAP_BASE;
  801. ioremap_bot = IOREMAP_BASE;
  802. #ifdef CONFIG_PCI
  803. pci_io_base = ISA_IO_BASE;
  804. #endif
  805. /* Select appropriate backend */
  806. if (firmware_has_feature(FW_FEATURE_PS3_LV1))
  807. ps3_early_mm_init();
  808. else if (firmware_has_feature(FW_FEATURE_LPAR))
  809. hpte_init_pseries();
  810. else if (IS_ENABLED(CONFIG_PPC_NATIVE))
  811. hpte_init_native();
  812. if (!mmu_hash_ops.hpte_insert)
  813. panic("hash__early_init_mmu: No MMU hash ops defined!\n");
  814. /* Initialize the MMU Hash table and create the linear mapping
  815. * of memory. Has to be done before SLB initialization as this is
  816. * currently where the page size encoding is obtained.
  817. */
  818. htab_initialize();
  819. pr_info("Initializing hash mmu with SLB\n");
  820. /* Initialize SLB management */
  821. slb_initialize();
  822. }
  823. #ifdef CONFIG_SMP
  824. void hash__early_init_mmu_secondary(void)
  825. {
  826. /* Initialize hash table for that CPU */
  827. if (!firmware_has_feature(FW_FEATURE_LPAR)) {
  828. if (!cpu_has_feature(CPU_FTR_ARCH_300))
  829. mtspr(SPRN_SDR1, _SDR1);
  830. else
  831. mtspr(SPRN_PTCR,
  832. __pa(partition_tb) | (PATB_SIZE_SHIFT - 12));
  833. }
  834. /* Initialize SLB */
  835. slb_initialize();
  836. }
  837. #endif /* CONFIG_SMP */
  838. /*
  839. * Called by asm hashtable.S for doing lazy icache flush
  840. */
  841. unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap)
  842. {
  843. struct page *page;
  844. if (!pfn_valid(pte_pfn(pte)))
  845. return pp;
  846. page = pte_page(pte);
  847. /* page is dirty */
  848. if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) {
  849. if (trap == 0x400) {
  850. flush_dcache_icache_page(page);
  851. set_bit(PG_arch_1, &page->flags);
  852. } else
  853. pp |= HPTE_R_N;
  854. }
  855. return pp;
  856. }
  857. #ifdef CONFIG_PPC_MM_SLICES
  858. static unsigned int get_paca_psize(unsigned long addr)
  859. {
  860. u64 lpsizes;
  861. unsigned char *hpsizes;
  862. unsigned long index, mask_index;
  863. if (addr < SLICE_LOW_TOP) {
  864. lpsizes = get_paca()->mm_ctx_low_slices_psize;
  865. index = GET_LOW_SLICE_INDEX(addr);
  866. return (lpsizes >> (index * 4)) & 0xF;
  867. }
  868. hpsizes = get_paca()->mm_ctx_high_slices_psize;
  869. index = GET_HIGH_SLICE_INDEX(addr);
  870. mask_index = index & 0x1;
  871. return (hpsizes[index >> 1] >> (mask_index * 4)) & 0xF;
  872. }
  873. #else
  874. unsigned int get_paca_psize(unsigned long addr)
  875. {
  876. return get_paca()->mm_ctx_user_psize;
  877. }
  878. #endif
  879. /*
  880. * Demote a segment to using 4k pages.
  881. * For now this makes the whole process use 4k pages.
  882. */
  883. #ifdef CONFIG_PPC_64K_PAGES
  884. void demote_segment_4k(struct mm_struct *mm, unsigned long addr)
  885. {
  886. if (get_slice_psize(mm, addr) == MMU_PAGE_4K)
  887. return;
  888. slice_set_range_psize(mm, addr, 1, MMU_PAGE_4K);
  889. copro_flush_all_slbs(mm);
  890. if ((get_paca_psize(addr) != MMU_PAGE_4K) && (current->mm == mm)) {
  891. copy_mm_to_paca(&mm->context);
  892. slb_flush_and_rebolt();
  893. }
  894. }
  895. #endif /* CONFIG_PPC_64K_PAGES */
  896. #ifdef CONFIG_PPC_SUBPAGE_PROT
  897. /*
  898. * This looks up a 2-bit protection code for a 4k subpage of a 64k page.
  899. * Userspace sets the subpage permissions using the subpage_prot system call.
  900. *
  901. * Result is 0: full permissions, _PAGE_RW: read-only,
  902. * _PAGE_RWX: no access.
  903. */
  904. static int subpage_protection(struct mm_struct *mm, unsigned long ea)
  905. {
  906. struct subpage_prot_table *spt = &mm->context.spt;
  907. u32 spp = 0;
  908. u32 **sbpm, *sbpp;
  909. if (ea >= spt->maxaddr)
  910. return 0;
  911. if (ea < 0x100000000UL) {
  912. /* addresses below 4GB use spt->low_prot */
  913. sbpm = spt->low_prot;
  914. } else {
  915. sbpm = spt->protptrs[ea >> SBP_L3_SHIFT];
  916. if (!sbpm)
  917. return 0;
  918. }
  919. sbpp = sbpm[(ea >> SBP_L2_SHIFT) & (SBP_L2_COUNT - 1)];
  920. if (!sbpp)
  921. return 0;
  922. spp = sbpp[(ea >> PAGE_SHIFT) & (SBP_L1_COUNT - 1)];
  923. /* extract 2-bit bitfield for this 4k subpage */
  924. spp >>= 30 - 2 * ((ea >> 12) & 0xf);
  925. /*
  926. * 0 -> full premission
  927. * 1 -> Read only
  928. * 2 -> no access.
  929. * We return the flag that need to be cleared.
  930. */
  931. spp = ((spp & 2) ? _PAGE_RWX : 0) | ((spp & 1) ? _PAGE_WRITE : 0);
  932. return spp;
  933. }
  934. #else /* CONFIG_PPC_SUBPAGE_PROT */
  935. static inline int subpage_protection(struct mm_struct *mm, unsigned long ea)
  936. {
  937. return 0;
  938. }
  939. #endif
  940. void hash_failure_debug(unsigned long ea, unsigned long access,
  941. unsigned long vsid, unsigned long trap,
  942. int ssize, int psize, int lpsize, unsigned long pte)
  943. {
  944. if (!printk_ratelimit())
  945. return;
  946. pr_info("mm: Hashing failure ! EA=0x%lx access=0x%lx current=%s\n",
  947. ea, access, current->comm);
  948. pr_info(" trap=0x%lx vsid=0x%lx ssize=%d base psize=%d psize %d pte=0x%lx\n",
  949. trap, vsid, ssize, psize, lpsize, pte);
  950. }
  951. static void check_paca_psize(unsigned long ea, struct mm_struct *mm,
  952. int psize, bool user_region)
  953. {
  954. if (user_region) {
  955. if (psize != get_paca_psize(ea)) {
  956. copy_mm_to_paca(&mm->context);
  957. slb_flush_and_rebolt();
  958. }
  959. } else if (get_paca()->vmalloc_sllp !=
  960. mmu_psize_defs[mmu_vmalloc_psize].sllp) {
  961. get_paca()->vmalloc_sllp =
  962. mmu_psize_defs[mmu_vmalloc_psize].sllp;
  963. slb_vmalloc_update();
  964. }
  965. }
  966. /* Result code is:
  967. * 0 - handled
  968. * 1 - normal page fault
  969. * -1 - critical hash insertion error
  970. * -2 - access not permitted by subpage protection mechanism
  971. */
  972. int hash_page_mm(struct mm_struct *mm, unsigned long ea,
  973. unsigned long access, unsigned long trap,
  974. unsigned long flags)
  975. {
  976. bool is_thp;
  977. enum ctx_state prev_state = exception_enter();
  978. pgd_t *pgdir;
  979. unsigned long vsid;
  980. pte_t *ptep;
  981. unsigned hugeshift;
  982. const struct cpumask *tmp;
  983. int rc, user_region = 0;
  984. int psize, ssize;
  985. DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n",
  986. ea, access, trap);
  987. trace_hash_fault(ea, access, trap);
  988. /* Get region & vsid */
  989. switch (REGION_ID(ea)) {
  990. case USER_REGION_ID:
  991. user_region = 1;
  992. if (! mm) {
  993. DBG_LOW(" user region with no mm !\n");
  994. rc = 1;
  995. goto bail;
  996. }
  997. psize = get_slice_psize(mm, ea);
  998. ssize = user_segment_size(ea);
  999. vsid = get_vsid(mm->context.id, ea, ssize);
  1000. break;
  1001. case VMALLOC_REGION_ID:
  1002. vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
  1003. if (ea < VMALLOC_END)
  1004. psize = mmu_vmalloc_psize;
  1005. else
  1006. psize = mmu_io_psize;
  1007. ssize = mmu_kernel_ssize;
  1008. break;
  1009. default:
  1010. /* Not a valid range
  1011. * Send the problem up to do_page_fault
  1012. */
  1013. rc = 1;
  1014. goto bail;
  1015. }
  1016. DBG_LOW(" mm=%p, mm->pgdir=%p, vsid=%016lx\n", mm, mm->pgd, vsid);
  1017. /* Bad address. */
  1018. if (!vsid) {
  1019. DBG_LOW("Bad address!\n");
  1020. rc = 1;
  1021. goto bail;
  1022. }
  1023. /* Get pgdir */
  1024. pgdir = mm->pgd;
  1025. if (pgdir == NULL) {
  1026. rc = 1;
  1027. goto bail;
  1028. }
  1029. /* Check CPU locality */
  1030. tmp = cpumask_of(smp_processor_id());
  1031. if (user_region && cpumask_equal(mm_cpumask(mm), tmp))
  1032. flags |= HPTE_LOCAL_UPDATE;
  1033. #ifndef CONFIG_PPC_64K_PAGES
  1034. /* If we use 4K pages and our psize is not 4K, then we might
  1035. * be hitting a special driver mapping, and need to align the
  1036. * address before we fetch the PTE.
  1037. *
  1038. * It could also be a hugepage mapping, in which case this is
  1039. * not necessary, but it's not harmful, either.
  1040. */
  1041. if (psize != MMU_PAGE_4K)
  1042. ea &= ~((1ul << mmu_psize_defs[psize].shift) - 1);
  1043. #endif /* CONFIG_PPC_64K_PAGES */
  1044. /* Get PTE and page size from page tables */
  1045. ptep = __find_linux_pte_or_hugepte(pgdir, ea, &is_thp, &hugeshift);
  1046. if (ptep == NULL || !pte_present(*ptep)) {
  1047. DBG_LOW(" no PTE !\n");
  1048. rc = 1;
  1049. goto bail;
  1050. }
  1051. /* Add _PAGE_PRESENT to the required access perm */
  1052. access |= _PAGE_PRESENT;
  1053. /* Pre-check access permissions (will be re-checked atomically
  1054. * in __hash_page_XX but this pre-check is a fast path
  1055. */
  1056. if (!check_pte_access(access, pte_val(*ptep))) {
  1057. DBG_LOW(" no access !\n");
  1058. rc = 1;
  1059. goto bail;
  1060. }
  1061. if (hugeshift) {
  1062. if (is_thp)
  1063. rc = __hash_page_thp(ea, access, vsid, (pmd_t *)ptep,
  1064. trap, flags, ssize, psize);
  1065. #ifdef CONFIG_HUGETLB_PAGE
  1066. else
  1067. rc = __hash_page_huge(ea, access, vsid, ptep, trap,
  1068. flags, ssize, hugeshift, psize);
  1069. #else
  1070. else {
  1071. /*
  1072. * if we have hugeshift, and is not transhuge with
  1073. * hugetlb disabled, something is really wrong.
  1074. */
  1075. rc = 1;
  1076. WARN_ON(1);
  1077. }
  1078. #endif
  1079. if (current->mm == mm)
  1080. check_paca_psize(ea, mm, psize, user_region);
  1081. goto bail;
  1082. }
  1083. #ifndef CONFIG_PPC_64K_PAGES
  1084. DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep));
  1085. #else
  1086. DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep),
  1087. pte_val(*(ptep + PTRS_PER_PTE)));
  1088. #endif
  1089. /* Do actual hashing */
  1090. #ifdef CONFIG_PPC_64K_PAGES
  1091. /* If H_PAGE_4K_PFN is set, make sure this is a 4k segment */
  1092. if ((pte_val(*ptep) & H_PAGE_4K_PFN) && psize == MMU_PAGE_64K) {
  1093. demote_segment_4k(mm, ea);
  1094. psize = MMU_PAGE_4K;
  1095. }
  1096. /* If this PTE is non-cacheable and we have restrictions on
  1097. * using non cacheable large pages, then we switch to 4k
  1098. */
  1099. if (mmu_ci_restrictions && psize == MMU_PAGE_64K && pte_ci(*ptep)) {
  1100. if (user_region) {
  1101. demote_segment_4k(mm, ea);
  1102. psize = MMU_PAGE_4K;
  1103. } else if (ea < VMALLOC_END) {
  1104. /*
  1105. * some driver did a non-cacheable mapping
  1106. * in vmalloc space, so switch vmalloc
  1107. * to 4k pages
  1108. */
  1109. printk(KERN_ALERT "Reducing vmalloc segment "
  1110. "to 4kB pages because of "
  1111. "non-cacheable mapping\n");
  1112. psize = mmu_vmalloc_psize = MMU_PAGE_4K;
  1113. copro_flush_all_slbs(mm);
  1114. }
  1115. }
  1116. #endif /* CONFIG_PPC_64K_PAGES */
  1117. if (current->mm == mm)
  1118. check_paca_psize(ea, mm, psize, user_region);
  1119. #ifdef CONFIG_PPC_64K_PAGES
  1120. if (psize == MMU_PAGE_64K)
  1121. rc = __hash_page_64K(ea, access, vsid, ptep, trap,
  1122. flags, ssize);
  1123. else
  1124. #endif /* CONFIG_PPC_64K_PAGES */
  1125. {
  1126. int spp = subpage_protection(mm, ea);
  1127. if (access & spp)
  1128. rc = -2;
  1129. else
  1130. rc = __hash_page_4K(ea, access, vsid, ptep, trap,
  1131. flags, ssize, spp);
  1132. }
  1133. /* Dump some info in case of hash insertion failure, they should
  1134. * never happen so it is really useful to know if/when they do
  1135. */
  1136. if (rc == -1)
  1137. hash_failure_debug(ea, access, vsid, trap, ssize, psize,
  1138. psize, pte_val(*ptep));
  1139. #ifndef CONFIG_PPC_64K_PAGES
  1140. DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep));
  1141. #else
  1142. DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep),
  1143. pte_val(*(ptep + PTRS_PER_PTE)));
  1144. #endif
  1145. DBG_LOW(" -> rc=%d\n", rc);
  1146. bail:
  1147. exception_exit(prev_state);
  1148. return rc;
  1149. }
  1150. EXPORT_SYMBOL_GPL(hash_page_mm);
  1151. int hash_page(unsigned long ea, unsigned long access, unsigned long trap,
  1152. unsigned long dsisr)
  1153. {
  1154. unsigned long flags = 0;
  1155. struct mm_struct *mm = current->mm;
  1156. if (REGION_ID(ea) == VMALLOC_REGION_ID)
  1157. mm = &init_mm;
  1158. if (dsisr & DSISR_NOHPTE)
  1159. flags |= HPTE_NOHPTE_UPDATE;
  1160. return hash_page_mm(mm, ea, access, trap, flags);
  1161. }
  1162. EXPORT_SYMBOL_GPL(hash_page);
  1163. int __hash_page(unsigned long ea, unsigned long msr, unsigned long trap,
  1164. unsigned long dsisr)
  1165. {
  1166. unsigned long access = _PAGE_PRESENT | _PAGE_READ;
  1167. unsigned long flags = 0;
  1168. struct mm_struct *mm = current->mm;
  1169. if (REGION_ID(ea) == VMALLOC_REGION_ID)
  1170. mm = &init_mm;
  1171. if (dsisr & DSISR_NOHPTE)
  1172. flags |= HPTE_NOHPTE_UPDATE;
  1173. if (dsisr & DSISR_ISSTORE)
  1174. access |= _PAGE_WRITE;
  1175. /*
  1176. * We set _PAGE_PRIVILEGED only when
  1177. * kernel mode access kernel space.
  1178. *
  1179. * _PAGE_PRIVILEGED is NOT set
  1180. * 1) when kernel mode access user space
  1181. * 2) user space access kernel space.
  1182. */
  1183. access |= _PAGE_PRIVILEGED;
  1184. if ((msr & MSR_PR) || (REGION_ID(ea) == USER_REGION_ID))
  1185. access &= ~_PAGE_PRIVILEGED;
  1186. if (trap == 0x400)
  1187. access |= _PAGE_EXEC;
  1188. return hash_page_mm(mm, ea, access, trap, flags);
  1189. }
  1190. #ifdef CONFIG_PPC_MM_SLICES
  1191. static bool should_hash_preload(struct mm_struct *mm, unsigned long ea)
  1192. {
  1193. int psize = get_slice_psize(mm, ea);
  1194. /* We only prefault standard pages for now */
  1195. if (unlikely(psize != mm->context.user_psize))
  1196. return false;
  1197. /*
  1198. * Don't prefault if subpage protection is enabled for the EA.
  1199. */
  1200. if (unlikely((psize == MMU_PAGE_4K) && subpage_protection(mm, ea)))
  1201. return false;
  1202. return true;
  1203. }
  1204. #else
  1205. static bool should_hash_preload(struct mm_struct *mm, unsigned long ea)
  1206. {
  1207. return true;
  1208. }
  1209. #endif
  1210. void hash_preload(struct mm_struct *mm, unsigned long ea,
  1211. unsigned long access, unsigned long trap)
  1212. {
  1213. int hugepage_shift;
  1214. unsigned long vsid;
  1215. pgd_t *pgdir;
  1216. pte_t *ptep;
  1217. unsigned long flags;
  1218. int rc, ssize, update_flags = 0;
  1219. BUG_ON(REGION_ID(ea) != USER_REGION_ID);
  1220. if (!should_hash_preload(mm, ea))
  1221. return;
  1222. DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx,"
  1223. " trap=%lx\n", mm, mm->pgd, ea, access, trap);
  1224. /* Get Linux PTE if available */
  1225. pgdir = mm->pgd;
  1226. if (pgdir == NULL)
  1227. return;
  1228. /* Get VSID */
  1229. ssize = user_segment_size(ea);
  1230. vsid = get_vsid(mm->context.id, ea, ssize);
  1231. if (!vsid)
  1232. return;
  1233. /*
  1234. * Hash doesn't like irqs. Walking linux page table with irq disabled
  1235. * saves us from holding multiple locks.
  1236. */
  1237. local_irq_save(flags);
  1238. /*
  1239. * THP pages use update_mmu_cache_pmd. We don't do
  1240. * hash preload there. Hence can ignore THP here
  1241. */
  1242. ptep = find_linux_pte_or_hugepte(pgdir, ea, NULL, &hugepage_shift);
  1243. if (!ptep)
  1244. goto out_exit;
  1245. WARN_ON(hugepage_shift);
  1246. #ifdef CONFIG_PPC_64K_PAGES
  1247. /* If either H_PAGE_4K_PFN or cache inhibited is set (and we are on
  1248. * a 64K kernel), then we don't preload, hash_page() will take
  1249. * care of it once we actually try to access the page.
  1250. * That way we don't have to duplicate all of the logic for segment
  1251. * page size demotion here
  1252. */
  1253. if ((pte_val(*ptep) & H_PAGE_4K_PFN) || pte_ci(*ptep))
  1254. goto out_exit;
  1255. #endif /* CONFIG_PPC_64K_PAGES */
  1256. /* Is that local to this CPU ? */
  1257. if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id())))
  1258. update_flags |= HPTE_LOCAL_UPDATE;
  1259. /* Hash it in */
  1260. #ifdef CONFIG_PPC_64K_PAGES
  1261. if (mm->context.user_psize == MMU_PAGE_64K)
  1262. rc = __hash_page_64K(ea, access, vsid, ptep, trap,
  1263. update_flags, ssize);
  1264. else
  1265. #endif /* CONFIG_PPC_64K_PAGES */
  1266. rc = __hash_page_4K(ea, access, vsid, ptep, trap, update_flags,
  1267. ssize, subpage_protection(mm, ea));
  1268. /* Dump some info in case of hash insertion failure, they should
  1269. * never happen so it is really useful to know if/when they do
  1270. */
  1271. if (rc == -1)
  1272. hash_failure_debug(ea, access, vsid, trap, ssize,
  1273. mm->context.user_psize,
  1274. mm->context.user_psize,
  1275. pte_val(*ptep));
  1276. out_exit:
  1277. local_irq_restore(flags);
  1278. }
  1279. /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  1280. * do not forget to update the assembly call site !
  1281. */
  1282. void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
  1283. unsigned long flags)
  1284. {
  1285. unsigned long hash, index, shift, hidx, slot;
  1286. int local = flags & HPTE_LOCAL_UPDATE;
  1287. DBG_LOW("flush_hash_page(vpn=%016lx)\n", vpn);
  1288. pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) {
  1289. hash = hpt_hash(vpn, shift, ssize);
  1290. hidx = __rpte_to_hidx(pte, index);
  1291. if (hidx & _PTEIDX_SECONDARY)
  1292. hash = ~hash;
  1293. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  1294. slot += hidx & _PTEIDX_GROUP_IX;
  1295. DBG_LOW(" sub %ld: hash=%lx, hidx=%lx\n", index, slot, hidx);
  1296. /*
  1297. * We use same base page size and actual psize, because we don't
  1298. * use these functions for hugepage
  1299. */
  1300. mmu_hash_ops.hpte_invalidate(slot, vpn, psize, psize,
  1301. ssize, local);
  1302. } pte_iterate_hashed_end();
  1303. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1304. /* Transactions are not aborted by tlbiel, only tlbie.
  1305. * Without, syncing a page back to a block device w/ PIO could pick up
  1306. * transactional data (bad!) so we force an abort here. Before the
  1307. * sync the page will be made read-only, which will flush_hash_page.
  1308. * BIG ISSUE here: if the kernel uses a page from userspace without
  1309. * unmapping it first, it may see the speculated version.
  1310. */
  1311. if (local && cpu_has_feature(CPU_FTR_TM) &&
  1312. current->thread.regs &&
  1313. MSR_TM_ACTIVE(current->thread.regs->msr)) {
  1314. tm_enable();
  1315. tm_abort(TM_CAUSE_TLBI);
  1316. }
  1317. #endif
  1318. }
  1319. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  1320. void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
  1321. pmd_t *pmdp, unsigned int psize, int ssize,
  1322. unsigned long flags)
  1323. {
  1324. int i, max_hpte_count, valid;
  1325. unsigned long s_addr;
  1326. unsigned char *hpte_slot_array;
  1327. unsigned long hidx, shift, vpn, hash, slot;
  1328. int local = flags & HPTE_LOCAL_UPDATE;
  1329. s_addr = addr & HPAGE_PMD_MASK;
  1330. hpte_slot_array = get_hpte_slot_array(pmdp);
  1331. /*
  1332. * IF we try to do a HUGE PTE update after a withdraw is done.
  1333. * we will find the below NULL. This happens when we do
  1334. * split_huge_page_pmd
  1335. */
  1336. if (!hpte_slot_array)
  1337. return;
  1338. if (mmu_hash_ops.hugepage_invalidate) {
  1339. mmu_hash_ops.hugepage_invalidate(vsid, s_addr, hpte_slot_array,
  1340. psize, ssize, local);
  1341. goto tm_abort;
  1342. }
  1343. /*
  1344. * No bluk hpte removal support, invalidate each entry
  1345. */
  1346. shift = mmu_psize_defs[psize].shift;
  1347. max_hpte_count = HPAGE_PMD_SIZE >> shift;
  1348. for (i = 0; i < max_hpte_count; i++) {
  1349. /*
  1350. * 8 bits per each hpte entries
  1351. * 000| [ secondary group (one bit) | hidx (3 bits) | valid bit]
  1352. */
  1353. valid = hpte_valid(hpte_slot_array, i);
  1354. if (!valid)
  1355. continue;
  1356. hidx = hpte_hash_index(hpte_slot_array, i);
  1357. /* get the vpn */
  1358. addr = s_addr + (i * (1ul << shift));
  1359. vpn = hpt_vpn(addr, vsid, ssize);
  1360. hash = hpt_hash(vpn, shift, ssize);
  1361. if (hidx & _PTEIDX_SECONDARY)
  1362. hash = ~hash;
  1363. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  1364. slot += hidx & _PTEIDX_GROUP_IX;
  1365. mmu_hash_ops.hpte_invalidate(slot, vpn, psize,
  1366. MMU_PAGE_16M, ssize, local);
  1367. }
  1368. tm_abort:
  1369. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1370. /* Transactions are not aborted by tlbiel, only tlbie.
  1371. * Without, syncing a page back to a block device w/ PIO could pick up
  1372. * transactional data (bad!) so we force an abort here. Before the
  1373. * sync the page will be made read-only, which will flush_hash_page.
  1374. * BIG ISSUE here: if the kernel uses a page from userspace without
  1375. * unmapping it first, it may see the speculated version.
  1376. */
  1377. if (local && cpu_has_feature(CPU_FTR_TM) &&
  1378. current->thread.regs &&
  1379. MSR_TM_ACTIVE(current->thread.regs->msr)) {
  1380. tm_enable();
  1381. tm_abort(TM_CAUSE_TLBI);
  1382. }
  1383. #endif
  1384. return;
  1385. }
  1386. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  1387. void flush_hash_range(unsigned long number, int local)
  1388. {
  1389. if (mmu_hash_ops.flush_hash_range)
  1390. mmu_hash_ops.flush_hash_range(number, local);
  1391. else {
  1392. int i;
  1393. struct ppc64_tlb_batch *batch =
  1394. this_cpu_ptr(&ppc64_tlb_batch);
  1395. for (i = 0; i < number; i++)
  1396. flush_hash_page(batch->vpn[i], batch->pte[i],
  1397. batch->psize, batch->ssize, local);
  1398. }
  1399. }
  1400. /*
  1401. * low_hash_fault is called when we the low level hash code failed
  1402. * to instert a PTE due to an hypervisor error
  1403. */
  1404. void low_hash_fault(struct pt_regs *regs, unsigned long address, int rc)
  1405. {
  1406. enum ctx_state prev_state = exception_enter();
  1407. if (user_mode(regs)) {
  1408. #ifdef CONFIG_PPC_SUBPAGE_PROT
  1409. if (rc == -2)
  1410. _exception(SIGSEGV, regs, SEGV_ACCERR, address);
  1411. else
  1412. #endif
  1413. _exception(SIGBUS, regs, BUS_ADRERR, address);
  1414. } else
  1415. bad_page_fault(regs, address, SIGBUS);
  1416. exception_exit(prev_state);
  1417. }
  1418. long hpte_insert_repeating(unsigned long hash, unsigned long vpn,
  1419. unsigned long pa, unsigned long rflags,
  1420. unsigned long vflags, int psize, int ssize)
  1421. {
  1422. unsigned long hpte_group;
  1423. long slot;
  1424. repeat:
  1425. hpte_group = ((hash & htab_hash_mask) *
  1426. HPTES_PER_GROUP) & ~0x7UL;
  1427. /* Insert into the hash table, primary slot */
  1428. slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, vflags,
  1429. psize, psize, ssize);
  1430. /* Primary is full, try the secondary */
  1431. if (unlikely(slot == -1)) {
  1432. hpte_group = ((~hash & htab_hash_mask) *
  1433. HPTES_PER_GROUP) & ~0x7UL;
  1434. slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags,
  1435. vflags | HPTE_V_SECONDARY,
  1436. psize, psize, ssize);
  1437. if (slot == -1) {
  1438. if (mftb() & 0x1)
  1439. hpte_group = ((hash & htab_hash_mask) *
  1440. HPTES_PER_GROUP)&~0x7UL;
  1441. mmu_hash_ops.hpte_remove(hpte_group);
  1442. goto repeat;
  1443. }
  1444. }
  1445. return slot;
  1446. }
  1447. #ifdef CONFIG_DEBUG_PAGEALLOC
  1448. static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi)
  1449. {
  1450. unsigned long hash;
  1451. unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize);
  1452. unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize);
  1453. unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL));
  1454. long ret;
  1455. hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize);
  1456. /* Don't create HPTE entries for bad address */
  1457. if (!vsid)
  1458. return;
  1459. ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode,
  1460. HPTE_V_BOLTED,
  1461. mmu_linear_psize, mmu_kernel_ssize);
  1462. BUG_ON (ret < 0);
  1463. spin_lock(&linear_map_hash_lock);
  1464. BUG_ON(linear_map_hash_slots[lmi] & 0x80);
  1465. linear_map_hash_slots[lmi] = ret | 0x80;
  1466. spin_unlock(&linear_map_hash_lock);
  1467. }
  1468. static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
  1469. {
  1470. unsigned long hash, hidx, slot;
  1471. unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize);
  1472. unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize);
  1473. hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize);
  1474. spin_lock(&linear_map_hash_lock);
  1475. BUG_ON(!(linear_map_hash_slots[lmi] & 0x80));
  1476. hidx = linear_map_hash_slots[lmi] & 0x7f;
  1477. linear_map_hash_slots[lmi] = 0;
  1478. spin_unlock(&linear_map_hash_lock);
  1479. if (hidx & _PTEIDX_SECONDARY)
  1480. hash = ~hash;
  1481. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  1482. slot += hidx & _PTEIDX_GROUP_IX;
  1483. mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize,
  1484. mmu_linear_psize,
  1485. mmu_kernel_ssize, 0);
  1486. }
  1487. void __kernel_map_pages(struct page *page, int numpages, int enable)
  1488. {
  1489. unsigned long flags, vaddr, lmi;
  1490. int i;
  1491. local_irq_save(flags);
  1492. for (i = 0; i < numpages; i++, page++) {
  1493. vaddr = (unsigned long)page_address(page);
  1494. lmi = __pa(vaddr) >> PAGE_SHIFT;
  1495. if (lmi >= linear_map_hash_count)
  1496. continue;
  1497. if (enable)
  1498. kernel_map_linear_page(vaddr, lmi);
  1499. else
  1500. kernel_unmap_linear_page(vaddr, lmi);
  1501. }
  1502. local_irq_restore(flags);
  1503. }
  1504. #endif /* CONFIG_DEBUG_PAGEALLOC */
  1505. void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base,
  1506. phys_addr_t first_memblock_size)
  1507. {
  1508. /* We don't currently support the first MEMBLOCK not mapping 0
  1509. * physical on those processors
  1510. */
  1511. BUG_ON(first_memblock_base != 0);
  1512. /* On LPAR systems, the first entry is our RMA region,
  1513. * non-LPAR 64-bit hash MMU systems don't have a limitation
  1514. * on real mode access, but using the first entry works well
  1515. * enough. We also clamp it to 1G to avoid some funky things
  1516. * such as RTAS bugs etc...
  1517. */
  1518. ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
  1519. /* Finally limit subsequent allocations */
  1520. memblock_set_current_limit(ppc64_rma_size);
  1521. }