pageattr.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * Copyright 2002 Andi Kleen, SuSE Labs.
  3. * Thanks to Ben LaHaise for precious feedback.
  4. */
  5. #include <linux/highmem.h>
  6. #include <linux/bootmem.h>
  7. #include <linux/module.h>
  8. #include <linux/sched.h>
  9. #include <linux/mm.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/debugfs.h>
  13. #include <linux/pfn.h>
  14. #include <linux/percpu.h>
  15. #include <linux/gfp.h>
  16. #include <linux/pci.h>
  17. #include <linux/vmalloc.h>
  18. #include <asm/e820.h>
  19. #include <asm/processor.h>
  20. #include <asm/tlbflush.h>
  21. #include <asm/sections.h>
  22. #include <asm/setup.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/pgalloc.h>
  25. #include <asm/proto.h>
  26. #include <asm/pat.h>
  27. /*
  28. * The current flushing context - we pass it instead of 5 arguments:
  29. */
  30. struct cpa_data {
  31. unsigned long *vaddr;
  32. pgd_t *pgd;
  33. pgprot_t mask_set;
  34. pgprot_t mask_clr;
  35. int numpages;
  36. int flags;
  37. unsigned long pfn;
  38. unsigned force_split : 1;
  39. int curpage;
  40. struct page **pages;
  41. };
  42. /*
  43. * Serialize cpa() (for !DEBUG_PAGEALLOC which uses large identity mappings)
  44. * using cpa_lock. So that we don't allow any other cpu, with stale large tlb
  45. * entries change the page attribute in parallel to some other cpu
  46. * splitting a large page entry along with changing the attribute.
  47. */
  48. static DEFINE_SPINLOCK(cpa_lock);
  49. #define CPA_FLUSHTLB 1
  50. #define CPA_ARRAY 2
  51. #define CPA_PAGES_ARRAY 4
  52. #ifdef CONFIG_PROC_FS
  53. static unsigned long direct_pages_count[PG_LEVEL_NUM];
  54. void update_page_count(int level, unsigned long pages)
  55. {
  56. /* Protect against CPA */
  57. spin_lock(&pgd_lock);
  58. direct_pages_count[level] += pages;
  59. spin_unlock(&pgd_lock);
  60. }
  61. static void split_page_count(int level)
  62. {
  63. direct_pages_count[level]--;
  64. direct_pages_count[level - 1] += PTRS_PER_PTE;
  65. }
  66. void arch_report_meminfo(struct seq_file *m)
  67. {
  68. seq_printf(m, "DirectMap4k: %8lu kB\n",
  69. direct_pages_count[PG_LEVEL_4K] << 2);
  70. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  71. seq_printf(m, "DirectMap2M: %8lu kB\n",
  72. direct_pages_count[PG_LEVEL_2M] << 11);
  73. #else
  74. seq_printf(m, "DirectMap4M: %8lu kB\n",
  75. direct_pages_count[PG_LEVEL_2M] << 12);
  76. #endif
  77. if (direct_gbpages)
  78. seq_printf(m, "DirectMap1G: %8lu kB\n",
  79. direct_pages_count[PG_LEVEL_1G] << 20);
  80. }
  81. #else
  82. static inline void split_page_count(int level) { }
  83. #endif
  84. #ifdef CONFIG_X86_64
  85. static inline unsigned long highmap_start_pfn(void)
  86. {
  87. return __pa_symbol(_text) >> PAGE_SHIFT;
  88. }
  89. static inline unsigned long highmap_end_pfn(void)
  90. {
  91. return __pa_symbol(roundup(_brk_end, PMD_SIZE)) >> PAGE_SHIFT;
  92. }
  93. #endif
  94. #ifdef CONFIG_DEBUG_PAGEALLOC
  95. # define debug_pagealloc 1
  96. #else
  97. # define debug_pagealloc 0
  98. #endif
  99. static inline int
  100. within(unsigned long addr, unsigned long start, unsigned long end)
  101. {
  102. return addr >= start && addr < end;
  103. }
  104. /*
  105. * Flushing functions
  106. */
  107. /**
  108. * clflush_cache_range - flush a cache range with clflush
  109. * @vaddr: virtual start address
  110. * @size: number of bytes to flush
  111. *
  112. * clflushopt is an unordered instruction which needs fencing with mfence or
  113. * sfence to avoid ordering issues.
  114. */
  115. void clflush_cache_range(void *vaddr, unsigned int size)
  116. {
  117. unsigned long clflush_mask = boot_cpu_data.x86_clflush_size - 1;
  118. void *vend = vaddr + size;
  119. void *p;
  120. mb();
  121. for (p = (void *)((unsigned long)vaddr & ~clflush_mask);
  122. p < vend; p += boot_cpu_data.x86_clflush_size)
  123. clflushopt(p);
  124. mb();
  125. }
  126. EXPORT_SYMBOL_GPL(clflush_cache_range);
  127. static void __cpa_flush_all(void *arg)
  128. {
  129. unsigned long cache = (unsigned long)arg;
  130. /*
  131. * Flush all to work around Errata in early athlons regarding
  132. * large page flushing.
  133. */
  134. __flush_tlb_all();
  135. if (cache && boot_cpu_data.x86 >= 4)
  136. wbinvd();
  137. }
  138. static void cpa_flush_all(unsigned long cache)
  139. {
  140. BUG_ON(irqs_disabled());
  141. on_each_cpu(__cpa_flush_all, (void *) cache, 1);
  142. }
  143. static void __cpa_flush_range(void *arg)
  144. {
  145. /*
  146. * We could optimize that further and do individual per page
  147. * tlb invalidates for a low number of pages. Caveat: we must
  148. * flush the high aliases on 64bit as well.
  149. */
  150. __flush_tlb_all();
  151. }
  152. static void cpa_flush_range(unsigned long start, int numpages, int cache)
  153. {
  154. unsigned int i, level;
  155. unsigned long addr;
  156. BUG_ON(irqs_disabled());
  157. WARN_ON(PAGE_ALIGN(start) != start);
  158. on_each_cpu(__cpa_flush_range, NULL, 1);
  159. if (!cache)
  160. return;
  161. /*
  162. * We only need to flush on one CPU,
  163. * clflush is a MESI-coherent instruction that
  164. * will cause all other CPUs to flush the same
  165. * cachelines:
  166. */
  167. for (i = 0, addr = start; i < numpages; i++, addr += PAGE_SIZE) {
  168. pte_t *pte = lookup_address(addr, &level);
  169. /*
  170. * Only flush present addresses:
  171. */
  172. if (pte && (pte_val(*pte) & _PAGE_PRESENT))
  173. clflush_cache_range((void *) addr, PAGE_SIZE);
  174. }
  175. }
  176. static void cpa_flush_array(unsigned long *start, int numpages, int cache,
  177. int in_flags, struct page **pages)
  178. {
  179. unsigned int i, level;
  180. unsigned long do_wbinvd = cache && numpages >= 1024; /* 4M threshold */
  181. BUG_ON(irqs_disabled());
  182. on_each_cpu(__cpa_flush_all, (void *) do_wbinvd, 1);
  183. if (!cache || do_wbinvd)
  184. return;
  185. /*
  186. * We only need to flush on one CPU,
  187. * clflush is a MESI-coherent instruction that
  188. * will cause all other CPUs to flush the same
  189. * cachelines:
  190. */
  191. for (i = 0; i < numpages; i++) {
  192. unsigned long addr;
  193. pte_t *pte;
  194. if (in_flags & CPA_PAGES_ARRAY)
  195. addr = (unsigned long)page_address(pages[i]);
  196. else
  197. addr = start[i];
  198. pte = lookup_address(addr, &level);
  199. /*
  200. * Only flush present addresses:
  201. */
  202. if (pte && (pte_val(*pte) & _PAGE_PRESENT))
  203. clflush_cache_range((void *)addr, PAGE_SIZE);
  204. }
  205. }
  206. /*
  207. * Certain areas of memory on x86 require very specific protection flags,
  208. * for example the BIOS area or kernel text. Callers don't always get this
  209. * right (again, ioremap() on BIOS memory is not uncommon) so this function
  210. * checks and fixes these known static required protection bits.
  211. */
  212. static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
  213. unsigned long pfn)
  214. {
  215. pgprot_t forbidden = __pgprot(0);
  216. /*
  217. * The BIOS area between 640k and 1Mb needs to be executable for
  218. * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
  219. */
  220. #ifdef CONFIG_PCI_BIOS
  221. if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
  222. pgprot_val(forbidden) |= _PAGE_NX;
  223. #endif
  224. /*
  225. * The kernel text needs to be executable for obvious reasons
  226. * Does not cover __inittext since that is gone later on. On
  227. * 64bit we do not enforce !NX on the low mapping
  228. */
  229. if (within(address, (unsigned long)_text, (unsigned long)_etext))
  230. pgprot_val(forbidden) |= _PAGE_NX;
  231. /*
  232. * The .rodata section needs to be read-only. Using the pfn
  233. * catches all aliases.
  234. */
  235. if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
  236. __pa_symbol(__end_rodata) >> PAGE_SHIFT))
  237. pgprot_val(forbidden) |= _PAGE_RW;
  238. #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
  239. /*
  240. * Once the kernel maps the text as RO (kernel_set_to_readonly is set),
  241. * kernel text mappings for the large page aligned text, rodata sections
  242. * will be always read-only. For the kernel identity mappings covering
  243. * the holes caused by this alignment can be anything that user asks.
  244. *
  245. * This will preserve the large page mappings for kernel text/data
  246. * at no extra cost.
  247. */
  248. if (kernel_set_to_readonly &&
  249. within(address, (unsigned long)_text,
  250. (unsigned long)__end_rodata_hpage_align)) {
  251. unsigned int level;
  252. /*
  253. * Don't enforce the !RW mapping for the kernel text mapping,
  254. * if the current mapping is already using small page mapping.
  255. * No need to work hard to preserve large page mappings in this
  256. * case.
  257. *
  258. * This also fixes the Linux Xen paravirt guest boot failure
  259. * (because of unexpected read-only mappings for kernel identity
  260. * mappings). In this paravirt guest case, the kernel text
  261. * mapping and the kernel identity mapping share the same
  262. * page-table pages. Thus we can't really use different
  263. * protections for the kernel text and identity mappings. Also,
  264. * these shared mappings are made of small page mappings.
  265. * Thus this don't enforce !RW mapping for small page kernel
  266. * text mapping logic will help Linux Xen parvirt guest boot
  267. * as well.
  268. */
  269. if (lookup_address(address, &level) && (level != PG_LEVEL_4K))
  270. pgprot_val(forbidden) |= _PAGE_RW;
  271. }
  272. #endif
  273. prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
  274. return prot;
  275. }
  276. /*
  277. * Lookup the page table entry for a virtual address in a specific pgd.
  278. * Return a pointer to the entry and the level of the mapping.
  279. */
  280. pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
  281. unsigned int *level)
  282. {
  283. pud_t *pud;
  284. pmd_t *pmd;
  285. *level = PG_LEVEL_NONE;
  286. if (pgd_none(*pgd))
  287. return NULL;
  288. pud = pud_offset(pgd, address);
  289. if (pud_none(*pud))
  290. return NULL;
  291. *level = PG_LEVEL_1G;
  292. if (pud_large(*pud) || !pud_present(*pud))
  293. return (pte_t *)pud;
  294. pmd = pmd_offset(pud, address);
  295. if (pmd_none(*pmd))
  296. return NULL;
  297. *level = PG_LEVEL_2M;
  298. if (pmd_large(*pmd) || !pmd_present(*pmd))
  299. return (pte_t *)pmd;
  300. *level = PG_LEVEL_4K;
  301. return pte_offset_kernel(pmd, address);
  302. }
  303. /*
  304. * Lookup the page table entry for a virtual address. Return a pointer
  305. * to the entry and the level of the mapping.
  306. *
  307. * Note: We return pud and pmd either when the entry is marked large
  308. * or when the present bit is not set. Otherwise we would return a
  309. * pointer to a nonexisting mapping.
  310. */
  311. pte_t *lookup_address(unsigned long address, unsigned int *level)
  312. {
  313. return lookup_address_in_pgd(pgd_offset_k(address), address, level);
  314. }
  315. EXPORT_SYMBOL_GPL(lookup_address);
  316. static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address,
  317. unsigned int *level)
  318. {
  319. if (cpa->pgd)
  320. return lookup_address_in_pgd(cpa->pgd + pgd_index(address),
  321. address, level);
  322. return lookup_address(address, level);
  323. }
  324. /*
  325. * Lookup the PMD entry for a virtual address. Return a pointer to the entry
  326. * or NULL if not present.
  327. */
  328. pmd_t *lookup_pmd_address(unsigned long address)
  329. {
  330. pgd_t *pgd;
  331. pud_t *pud;
  332. pgd = pgd_offset_k(address);
  333. if (pgd_none(*pgd))
  334. return NULL;
  335. pud = pud_offset(pgd, address);
  336. if (pud_none(*pud) || pud_large(*pud) || !pud_present(*pud))
  337. return NULL;
  338. return pmd_offset(pud, address);
  339. }
  340. /*
  341. * This is necessary because __pa() does not work on some
  342. * kinds of memory, like vmalloc() or the alloc_remap()
  343. * areas on 32-bit NUMA systems. The percpu areas can
  344. * end up in this kind of memory, for instance.
  345. *
  346. * This could be optimized, but it is only intended to be
  347. * used at inititalization time, and keeping it
  348. * unoptimized should increase the testing coverage for
  349. * the more obscure platforms.
  350. */
  351. phys_addr_t slow_virt_to_phys(void *__virt_addr)
  352. {
  353. unsigned long virt_addr = (unsigned long)__virt_addr;
  354. phys_addr_t phys_addr;
  355. unsigned long offset;
  356. enum pg_level level;
  357. unsigned long pmask;
  358. pte_t *pte;
  359. pte = lookup_address(virt_addr, &level);
  360. BUG_ON(!pte);
  361. pmask = page_level_mask(level);
  362. offset = virt_addr & ~pmask;
  363. phys_addr = (phys_addr_t)pte_pfn(*pte) << PAGE_SHIFT;
  364. return (phys_addr | offset);
  365. }
  366. EXPORT_SYMBOL_GPL(slow_virt_to_phys);
  367. /*
  368. * Set the new pmd in all the pgds we know about:
  369. */
  370. static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
  371. {
  372. /* change init_mm */
  373. set_pte_atomic(kpte, pte);
  374. #ifdef CONFIG_X86_32
  375. if (!SHARED_KERNEL_PMD) {
  376. struct page *page;
  377. list_for_each_entry(page, &pgd_list, lru) {
  378. pgd_t *pgd;
  379. pud_t *pud;
  380. pmd_t *pmd;
  381. pgd = (pgd_t *)page_address(page) + pgd_index(address);
  382. pud = pud_offset(pgd, address);
  383. pmd = pmd_offset(pud, address);
  384. set_pte_atomic((pte_t *)pmd, pte);
  385. }
  386. }
  387. #endif
  388. }
  389. static int
  390. try_preserve_large_page(pte_t *kpte, unsigned long address,
  391. struct cpa_data *cpa)
  392. {
  393. unsigned long nextpage_addr, numpages, pmask, psize, addr, pfn;
  394. pte_t new_pte, old_pte, *tmp;
  395. pgprot_t old_prot, new_prot, req_prot;
  396. int i, do_split = 1;
  397. enum pg_level level;
  398. if (cpa->force_split)
  399. return 1;
  400. spin_lock(&pgd_lock);
  401. /*
  402. * Check for races, another CPU might have split this page
  403. * up already:
  404. */
  405. tmp = _lookup_address_cpa(cpa, address, &level);
  406. if (tmp != kpte)
  407. goto out_unlock;
  408. switch (level) {
  409. case PG_LEVEL_2M:
  410. #ifdef CONFIG_X86_64
  411. case PG_LEVEL_1G:
  412. #endif
  413. psize = page_level_size(level);
  414. pmask = page_level_mask(level);
  415. break;
  416. default:
  417. do_split = -EINVAL;
  418. goto out_unlock;
  419. }
  420. /*
  421. * Calculate the number of pages, which fit into this large
  422. * page starting at address:
  423. */
  424. nextpage_addr = (address + psize) & pmask;
  425. numpages = (nextpage_addr - address) >> PAGE_SHIFT;
  426. if (numpages < cpa->numpages)
  427. cpa->numpages = numpages;
  428. /*
  429. * We are safe now. Check whether the new pgprot is the same:
  430. * Convert protection attributes to 4k-format, as cpa->mask* are set
  431. * up accordingly.
  432. */
  433. old_pte = *kpte;
  434. old_prot = req_prot = pgprot_large_2_4k(pte_pgprot(old_pte));
  435. pgprot_val(req_prot) &= ~pgprot_val(cpa->mask_clr);
  436. pgprot_val(req_prot) |= pgprot_val(cpa->mask_set);
  437. /*
  438. * req_prot is in format of 4k pages. It must be converted to large
  439. * page format: the caching mode includes the PAT bit located at
  440. * different bit positions in the two formats.
  441. */
  442. req_prot = pgprot_4k_2_large(req_prot);
  443. /*
  444. * Set the PSE and GLOBAL flags only if the PRESENT flag is
  445. * set otherwise pmd_present/pmd_huge will return true even on
  446. * a non present pmd. The canon_pgprot will clear _PAGE_GLOBAL
  447. * for the ancient hardware that doesn't support it.
  448. */
  449. if (pgprot_val(req_prot) & _PAGE_PRESENT)
  450. pgprot_val(req_prot) |= _PAGE_PSE | _PAGE_GLOBAL;
  451. else
  452. pgprot_val(req_prot) &= ~(_PAGE_PSE | _PAGE_GLOBAL);
  453. req_prot = canon_pgprot(req_prot);
  454. /*
  455. * old_pte points to the large page base address. So we need
  456. * to add the offset of the virtual address:
  457. */
  458. pfn = pte_pfn(old_pte) + ((address & (psize - 1)) >> PAGE_SHIFT);
  459. cpa->pfn = pfn;
  460. new_prot = static_protections(req_prot, address, pfn);
  461. /*
  462. * We need to check the full range, whether
  463. * static_protection() requires a different pgprot for one of
  464. * the pages in the range we try to preserve:
  465. */
  466. addr = address & pmask;
  467. pfn = pte_pfn(old_pte);
  468. for (i = 0; i < (psize >> PAGE_SHIFT); i++, addr += PAGE_SIZE, pfn++) {
  469. pgprot_t chk_prot = static_protections(req_prot, addr, pfn);
  470. if (pgprot_val(chk_prot) != pgprot_val(new_prot))
  471. goto out_unlock;
  472. }
  473. /*
  474. * If there are no changes, return. maxpages has been updated
  475. * above:
  476. */
  477. if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
  478. do_split = 0;
  479. goto out_unlock;
  480. }
  481. /*
  482. * We need to change the attributes. Check, whether we can
  483. * change the large page in one go. We request a split, when
  484. * the address is not aligned and the number of pages is
  485. * smaller than the number of pages in the large page. Note
  486. * that we limited the number of possible pages already to
  487. * the number of pages in the large page.
  488. */
  489. if (address == (address & pmask) && cpa->numpages == (psize >> PAGE_SHIFT)) {
  490. /*
  491. * The address is aligned and the number of pages
  492. * covers the full page.
  493. */
  494. new_pte = pfn_pte(pte_pfn(old_pte), new_prot);
  495. __set_pmd_pte(kpte, address, new_pte);
  496. cpa->flags |= CPA_FLUSHTLB;
  497. do_split = 0;
  498. }
  499. out_unlock:
  500. spin_unlock(&pgd_lock);
  501. return do_split;
  502. }
  503. static int
  504. __split_large_page(struct cpa_data *cpa, pte_t *kpte, unsigned long address,
  505. struct page *base)
  506. {
  507. pte_t *pbase = (pte_t *)page_address(base);
  508. unsigned long pfn, pfninc = 1;
  509. unsigned int i, level;
  510. pte_t *tmp;
  511. pgprot_t ref_prot;
  512. spin_lock(&pgd_lock);
  513. /*
  514. * Check for races, another CPU might have split this page
  515. * up for us already:
  516. */
  517. tmp = _lookup_address_cpa(cpa, address, &level);
  518. if (tmp != kpte) {
  519. spin_unlock(&pgd_lock);
  520. return 1;
  521. }
  522. paravirt_alloc_pte(&init_mm, page_to_pfn(base));
  523. ref_prot = pte_pgprot(pte_clrhuge(*kpte));
  524. /* promote PAT bit to correct position */
  525. if (level == PG_LEVEL_2M)
  526. ref_prot = pgprot_large_2_4k(ref_prot);
  527. #ifdef CONFIG_X86_64
  528. if (level == PG_LEVEL_1G) {
  529. pfninc = PMD_PAGE_SIZE >> PAGE_SHIFT;
  530. /*
  531. * Set the PSE flags only if the PRESENT flag is set
  532. * otherwise pmd_present/pmd_huge will return true
  533. * even on a non present pmd.
  534. */
  535. if (pgprot_val(ref_prot) & _PAGE_PRESENT)
  536. pgprot_val(ref_prot) |= _PAGE_PSE;
  537. else
  538. pgprot_val(ref_prot) &= ~_PAGE_PSE;
  539. }
  540. #endif
  541. /*
  542. * Set the GLOBAL flags only if the PRESENT flag is set
  543. * otherwise pmd/pte_present will return true even on a non
  544. * present pmd/pte. The canon_pgprot will clear _PAGE_GLOBAL
  545. * for the ancient hardware that doesn't support it.
  546. */
  547. if (pgprot_val(ref_prot) & _PAGE_PRESENT)
  548. pgprot_val(ref_prot) |= _PAGE_GLOBAL;
  549. else
  550. pgprot_val(ref_prot) &= ~_PAGE_GLOBAL;
  551. /*
  552. * Get the target pfn from the original entry:
  553. */
  554. pfn = pte_pfn(*kpte);
  555. for (i = 0; i < PTRS_PER_PTE; i++, pfn += pfninc)
  556. set_pte(&pbase[i], pfn_pte(pfn, canon_pgprot(ref_prot)));
  557. if (pfn_range_is_mapped(PFN_DOWN(__pa(address)),
  558. PFN_DOWN(__pa(address)) + 1))
  559. split_page_count(level);
  560. /*
  561. * Install the new, split up pagetable.
  562. *
  563. * We use the standard kernel pagetable protections for the new
  564. * pagetable protections, the actual ptes set above control the
  565. * primary protection behavior:
  566. */
  567. __set_pmd_pte(kpte, address, mk_pte(base, __pgprot(_KERNPG_TABLE)));
  568. /*
  569. * Intel Atom errata AAH41 workaround.
  570. *
  571. * The real fix should be in hw or in a microcode update, but
  572. * we also probabilistically try to reduce the window of having
  573. * a large TLB mixed with 4K TLBs while instruction fetches are
  574. * going on.
  575. */
  576. __flush_tlb_all();
  577. spin_unlock(&pgd_lock);
  578. return 0;
  579. }
  580. static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
  581. unsigned long address)
  582. {
  583. struct page *base;
  584. if (!debug_pagealloc)
  585. spin_unlock(&cpa_lock);
  586. base = alloc_pages(GFP_KERNEL | __GFP_NOTRACK, 0);
  587. if (!debug_pagealloc)
  588. spin_lock(&cpa_lock);
  589. if (!base)
  590. return -ENOMEM;
  591. if (__split_large_page(cpa, kpte, address, base))
  592. __free_page(base);
  593. return 0;
  594. }
  595. static bool try_to_free_pte_page(pte_t *pte)
  596. {
  597. int i;
  598. for (i = 0; i < PTRS_PER_PTE; i++)
  599. if (!pte_none(pte[i]))
  600. return false;
  601. free_page((unsigned long)pte);
  602. return true;
  603. }
  604. static bool try_to_free_pmd_page(pmd_t *pmd)
  605. {
  606. int i;
  607. for (i = 0; i < PTRS_PER_PMD; i++)
  608. if (!pmd_none(pmd[i]))
  609. return false;
  610. free_page((unsigned long)pmd);
  611. return true;
  612. }
  613. static bool try_to_free_pud_page(pud_t *pud)
  614. {
  615. int i;
  616. for (i = 0; i < PTRS_PER_PUD; i++)
  617. if (!pud_none(pud[i]))
  618. return false;
  619. free_page((unsigned long)pud);
  620. return true;
  621. }
  622. static bool unmap_pte_range(pmd_t *pmd, unsigned long start, unsigned long end)
  623. {
  624. pte_t *pte = pte_offset_kernel(pmd, start);
  625. while (start < end) {
  626. set_pte(pte, __pte(0));
  627. start += PAGE_SIZE;
  628. pte++;
  629. }
  630. if (try_to_free_pte_page((pte_t *)pmd_page_vaddr(*pmd))) {
  631. pmd_clear(pmd);
  632. return true;
  633. }
  634. return false;
  635. }
  636. static void __unmap_pmd_range(pud_t *pud, pmd_t *pmd,
  637. unsigned long start, unsigned long end)
  638. {
  639. if (unmap_pte_range(pmd, start, end))
  640. if (try_to_free_pmd_page((pmd_t *)pud_page_vaddr(*pud)))
  641. pud_clear(pud);
  642. }
  643. static void unmap_pmd_range(pud_t *pud, unsigned long start, unsigned long end)
  644. {
  645. pmd_t *pmd = pmd_offset(pud, start);
  646. /*
  647. * Not on a 2MB page boundary?
  648. */
  649. if (start & (PMD_SIZE - 1)) {
  650. unsigned long next_page = (start + PMD_SIZE) & PMD_MASK;
  651. unsigned long pre_end = min_t(unsigned long, end, next_page);
  652. __unmap_pmd_range(pud, pmd, start, pre_end);
  653. start = pre_end;
  654. pmd++;
  655. }
  656. /*
  657. * Try to unmap in 2M chunks.
  658. */
  659. while (end - start >= PMD_SIZE) {
  660. if (pmd_large(*pmd))
  661. pmd_clear(pmd);
  662. else
  663. __unmap_pmd_range(pud, pmd, start, start + PMD_SIZE);
  664. start += PMD_SIZE;
  665. pmd++;
  666. }
  667. /*
  668. * 4K leftovers?
  669. */
  670. if (start < end)
  671. return __unmap_pmd_range(pud, pmd, start, end);
  672. /*
  673. * Try again to free the PMD page if haven't succeeded above.
  674. */
  675. if (!pud_none(*pud))
  676. if (try_to_free_pmd_page((pmd_t *)pud_page_vaddr(*pud)))
  677. pud_clear(pud);
  678. }
  679. static void unmap_pud_range(pgd_t *pgd, unsigned long start, unsigned long end)
  680. {
  681. pud_t *pud = pud_offset(pgd, start);
  682. /*
  683. * Not on a GB page boundary?
  684. */
  685. if (start & (PUD_SIZE - 1)) {
  686. unsigned long next_page = (start + PUD_SIZE) & PUD_MASK;
  687. unsigned long pre_end = min_t(unsigned long, end, next_page);
  688. unmap_pmd_range(pud, start, pre_end);
  689. start = pre_end;
  690. pud++;
  691. }
  692. /*
  693. * Try to unmap in 1G chunks?
  694. */
  695. while (end - start >= PUD_SIZE) {
  696. if (pud_large(*pud))
  697. pud_clear(pud);
  698. else
  699. unmap_pmd_range(pud, start, start + PUD_SIZE);
  700. start += PUD_SIZE;
  701. pud++;
  702. }
  703. /*
  704. * 2M leftovers?
  705. */
  706. if (start < end)
  707. unmap_pmd_range(pud, start, end);
  708. /*
  709. * No need to try to free the PUD page because we'll free it in
  710. * populate_pgd's error path
  711. */
  712. }
  713. static void unmap_pgd_range(pgd_t *root, unsigned long addr, unsigned long end)
  714. {
  715. pgd_t *pgd_entry = root + pgd_index(addr);
  716. unmap_pud_range(pgd_entry, addr, end);
  717. if (try_to_free_pud_page((pud_t *)pgd_page_vaddr(*pgd_entry)))
  718. pgd_clear(pgd_entry);
  719. }
  720. static int alloc_pte_page(pmd_t *pmd)
  721. {
  722. pte_t *pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK);
  723. if (!pte)
  724. return -1;
  725. set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
  726. return 0;
  727. }
  728. static int alloc_pmd_page(pud_t *pud)
  729. {
  730. pmd_t *pmd = (pmd_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK);
  731. if (!pmd)
  732. return -1;
  733. set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
  734. return 0;
  735. }
  736. static void populate_pte(struct cpa_data *cpa,
  737. unsigned long start, unsigned long end,
  738. unsigned num_pages, pmd_t *pmd, pgprot_t pgprot)
  739. {
  740. pte_t *pte;
  741. pte = pte_offset_kernel(pmd, start);
  742. while (num_pages-- && start < end) {
  743. /* deal with the NX bit */
  744. if (!(pgprot_val(pgprot) & _PAGE_NX))
  745. cpa->pfn &= ~_PAGE_NX;
  746. set_pte(pte, pfn_pte(cpa->pfn >> PAGE_SHIFT, pgprot));
  747. start += PAGE_SIZE;
  748. cpa->pfn += PAGE_SIZE;
  749. pte++;
  750. }
  751. }
  752. static int populate_pmd(struct cpa_data *cpa,
  753. unsigned long start, unsigned long end,
  754. unsigned num_pages, pud_t *pud, pgprot_t pgprot)
  755. {
  756. unsigned int cur_pages = 0;
  757. pmd_t *pmd;
  758. pgprot_t pmd_pgprot;
  759. /*
  760. * Not on a 2M boundary?
  761. */
  762. if (start & (PMD_SIZE - 1)) {
  763. unsigned long pre_end = start + (num_pages << PAGE_SHIFT);
  764. unsigned long next_page = (start + PMD_SIZE) & PMD_MASK;
  765. pre_end = min_t(unsigned long, pre_end, next_page);
  766. cur_pages = (pre_end - start) >> PAGE_SHIFT;
  767. cur_pages = min_t(unsigned int, num_pages, cur_pages);
  768. /*
  769. * Need a PTE page?
  770. */
  771. pmd = pmd_offset(pud, start);
  772. if (pmd_none(*pmd))
  773. if (alloc_pte_page(pmd))
  774. return -1;
  775. populate_pte(cpa, start, pre_end, cur_pages, pmd, pgprot);
  776. start = pre_end;
  777. }
  778. /*
  779. * We mapped them all?
  780. */
  781. if (num_pages == cur_pages)
  782. return cur_pages;
  783. pmd_pgprot = pgprot_4k_2_large(pgprot);
  784. while (end - start >= PMD_SIZE) {
  785. /*
  786. * We cannot use a 1G page so allocate a PMD page if needed.
  787. */
  788. if (pud_none(*pud))
  789. if (alloc_pmd_page(pud))
  790. return -1;
  791. pmd = pmd_offset(pud, start);
  792. set_pmd(pmd, __pmd(cpa->pfn | _PAGE_PSE |
  793. massage_pgprot(pmd_pgprot)));
  794. start += PMD_SIZE;
  795. cpa->pfn += PMD_SIZE;
  796. cur_pages += PMD_SIZE >> PAGE_SHIFT;
  797. }
  798. /*
  799. * Map trailing 4K pages.
  800. */
  801. if (start < end) {
  802. pmd = pmd_offset(pud, start);
  803. if (pmd_none(*pmd))
  804. if (alloc_pte_page(pmd))
  805. return -1;
  806. populate_pte(cpa, start, end, num_pages - cur_pages,
  807. pmd, pgprot);
  808. }
  809. return num_pages;
  810. }
  811. static int populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd,
  812. pgprot_t pgprot)
  813. {
  814. pud_t *pud;
  815. unsigned long end;
  816. int cur_pages = 0;
  817. pgprot_t pud_pgprot;
  818. end = start + (cpa->numpages << PAGE_SHIFT);
  819. /*
  820. * Not on a Gb page boundary? => map everything up to it with
  821. * smaller pages.
  822. */
  823. if (start & (PUD_SIZE - 1)) {
  824. unsigned long pre_end;
  825. unsigned long next_page = (start + PUD_SIZE) & PUD_MASK;
  826. pre_end = min_t(unsigned long, end, next_page);
  827. cur_pages = (pre_end - start) >> PAGE_SHIFT;
  828. cur_pages = min_t(int, (int)cpa->numpages, cur_pages);
  829. pud = pud_offset(pgd, start);
  830. /*
  831. * Need a PMD page?
  832. */
  833. if (pud_none(*pud))
  834. if (alloc_pmd_page(pud))
  835. return -1;
  836. cur_pages = populate_pmd(cpa, start, pre_end, cur_pages,
  837. pud, pgprot);
  838. if (cur_pages < 0)
  839. return cur_pages;
  840. start = pre_end;
  841. }
  842. /* We mapped them all? */
  843. if (cpa->numpages == cur_pages)
  844. return cur_pages;
  845. pud = pud_offset(pgd, start);
  846. pud_pgprot = pgprot_4k_2_large(pgprot);
  847. /*
  848. * Map everything starting from the Gb boundary, possibly with 1G pages
  849. */
  850. while (end - start >= PUD_SIZE) {
  851. set_pud(pud, __pud(cpa->pfn | _PAGE_PSE |
  852. massage_pgprot(pud_pgprot)));
  853. start += PUD_SIZE;
  854. cpa->pfn += PUD_SIZE;
  855. cur_pages += PUD_SIZE >> PAGE_SHIFT;
  856. pud++;
  857. }
  858. /* Map trailing leftover */
  859. if (start < end) {
  860. int tmp;
  861. pud = pud_offset(pgd, start);
  862. if (pud_none(*pud))
  863. if (alloc_pmd_page(pud))
  864. return -1;
  865. tmp = populate_pmd(cpa, start, end, cpa->numpages - cur_pages,
  866. pud, pgprot);
  867. if (tmp < 0)
  868. return cur_pages;
  869. cur_pages += tmp;
  870. }
  871. return cur_pages;
  872. }
  873. /*
  874. * Restrictions for kernel page table do not necessarily apply when mapping in
  875. * an alternate PGD.
  876. */
  877. static int populate_pgd(struct cpa_data *cpa, unsigned long addr)
  878. {
  879. pgprot_t pgprot = __pgprot(_KERNPG_TABLE);
  880. pud_t *pud = NULL; /* shut up gcc */
  881. pgd_t *pgd_entry;
  882. int ret;
  883. pgd_entry = cpa->pgd + pgd_index(addr);
  884. /*
  885. * Allocate a PUD page and hand it down for mapping.
  886. */
  887. if (pgd_none(*pgd_entry)) {
  888. pud = (pud_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK);
  889. if (!pud)
  890. return -1;
  891. set_pgd(pgd_entry, __pgd(__pa(pud) | _KERNPG_TABLE));
  892. }
  893. pgprot_val(pgprot) &= ~pgprot_val(cpa->mask_clr);
  894. pgprot_val(pgprot) |= pgprot_val(cpa->mask_set);
  895. ret = populate_pud(cpa, addr, pgd_entry, pgprot);
  896. if (ret < 0) {
  897. unmap_pgd_range(cpa->pgd, addr,
  898. addr + (cpa->numpages << PAGE_SHIFT));
  899. return ret;
  900. }
  901. cpa->numpages = ret;
  902. return 0;
  903. }
  904. static int __cpa_process_fault(struct cpa_data *cpa, unsigned long vaddr,
  905. int primary)
  906. {
  907. if (cpa->pgd)
  908. return populate_pgd(cpa, vaddr);
  909. /*
  910. * Ignore all non primary paths.
  911. */
  912. if (!primary)
  913. return 0;
  914. /*
  915. * Ignore the NULL PTE for kernel identity mapping, as it is expected
  916. * to have holes.
  917. * Also set numpages to '1' indicating that we processed cpa req for
  918. * one virtual address page and its pfn. TBD: numpages can be set based
  919. * on the initial value and the level returned by lookup_address().
  920. */
  921. if (within(vaddr, PAGE_OFFSET,
  922. PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT))) {
  923. cpa->numpages = 1;
  924. cpa->pfn = __pa(vaddr) >> PAGE_SHIFT;
  925. return 0;
  926. } else {
  927. WARN(1, KERN_WARNING "CPA: called for zero pte. "
  928. "vaddr = %lx cpa->vaddr = %lx\n", vaddr,
  929. *cpa->vaddr);
  930. return -EFAULT;
  931. }
  932. }
  933. static int __change_page_attr(struct cpa_data *cpa, int primary)
  934. {
  935. unsigned long address;
  936. int do_split, err;
  937. unsigned int level;
  938. pte_t *kpte, old_pte;
  939. if (cpa->flags & CPA_PAGES_ARRAY) {
  940. struct page *page = cpa->pages[cpa->curpage];
  941. if (unlikely(PageHighMem(page)))
  942. return 0;
  943. address = (unsigned long)page_address(page);
  944. } else if (cpa->flags & CPA_ARRAY)
  945. address = cpa->vaddr[cpa->curpage];
  946. else
  947. address = *cpa->vaddr;
  948. repeat:
  949. kpte = _lookup_address_cpa(cpa, address, &level);
  950. if (!kpte)
  951. return __cpa_process_fault(cpa, address, primary);
  952. old_pte = *kpte;
  953. if (!pte_val(old_pte))
  954. return __cpa_process_fault(cpa, address, primary);
  955. if (level == PG_LEVEL_4K) {
  956. pte_t new_pte;
  957. pgprot_t new_prot = pte_pgprot(old_pte);
  958. unsigned long pfn = pte_pfn(old_pte);
  959. pgprot_val(new_prot) &= ~pgprot_val(cpa->mask_clr);
  960. pgprot_val(new_prot) |= pgprot_val(cpa->mask_set);
  961. new_prot = static_protections(new_prot, address, pfn);
  962. /*
  963. * Set the GLOBAL flags only if the PRESENT flag is
  964. * set otherwise pte_present will return true even on
  965. * a non present pte. The canon_pgprot will clear
  966. * _PAGE_GLOBAL for the ancient hardware that doesn't
  967. * support it.
  968. */
  969. if (pgprot_val(new_prot) & _PAGE_PRESENT)
  970. pgprot_val(new_prot) |= _PAGE_GLOBAL;
  971. else
  972. pgprot_val(new_prot) &= ~_PAGE_GLOBAL;
  973. /*
  974. * We need to keep the pfn from the existing PTE,
  975. * after all we're only going to change it's attributes
  976. * not the memory it points to
  977. */
  978. new_pte = pfn_pte(pfn, canon_pgprot(new_prot));
  979. cpa->pfn = pfn;
  980. /*
  981. * Do we really change anything ?
  982. */
  983. if (pte_val(old_pte) != pte_val(new_pte)) {
  984. set_pte_atomic(kpte, new_pte);
  985. cpa->flags |= CPA_FLUSHTLB;
  986. }
  987. cpa->numpages = 1;
  988. return 0;
  989. }
  990. /*
  991. * Check, whether we can keep the large page intact
  992. * and just change the pte:
  993. */
  994. do_split = try_preserve_large_page(kpte, address, cpa);
  995. /*
  996. * When the range fits into the existing large page,
  997. * return. cp->numpages and cpa->tlbflush have been updated in
  998. * try_large_page:
  999. */
  1000. if (do_split <= 0)
  1001. return do_split;
  1002. /*
  1003. * We have to split the large page:
  1004. */
  1005. err = split_large_page(cpa, kpte, address);
  1006. if (!err) {
  1007. /*
  1008. * Do a global flush tlb after splitting the large page
  1009. * and before we do the actual change page attribute in the PTE.
  1010. *
  1011. * With out this, we violate the TLB application note, that says
  1012. * "The TLBs may contain both ordinary and large-page
  1013. * translations for a 4-KByte range of linear addresses. This
  1014. * may occur if software modifies the paging structures so that
  1015. * the page size used for the address range changes. If the two
  1016. * translations differ with respect to page frame or attributes
  1017. * (e.g., permissions), processor behavior is undefined and may
  1018. * be implementation-specific."
  1019. *
  1020. * We do this global tlb flush inside the cpa_lock, so that we
  1021. * don't allow any other cpu, with stale tlb entries change the
  1022. * page attribute in parallel, that also falls into the
  1023. * just split large page entry.
  1024. */
  1025. flush_tlb_all();
  1026. goto repeat;
  1027. }
  1028. return err;
  1029. }
  1030. static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias);
  1031. static int cpa_process_alias(struct cpa_data *cpa)
  1032. {
  1033. struct cpa_data alias_cpa;
  1034. unsigned long laddr = (unsigned long)__va(cpa->pfn << PAGE_SHIFT);
  1035. unsigned long vaddr;
  1036. int ret;
  1037. if (!pfn_range_is_mapped(cpa->pfn, cpa->pfn + 1))
  1038. return 0;
  1039. /*
  1040. * No need to redo, when the primary call touched the direct
  1041. * mapping already:
  1042. */
  1043. if (cpa->flags & CPA_PAGES_ARRAY) {
  1044. struct page *page = cpa->pages[cpa->curpage];
  1045. if (unlikely(PageHighMem(page)))
  1046. return 0;
  1047. vaddr = (unsigned long)page_address(page);
  1048. } else if (cpa->flags & CPA_ARRAY)
  1049. vaddr = cpa->vaddr[cpa->curpage];
  1050. else
  1051. vaddr = *cpa->vaddr;
  1052. if (!(within(vaddr, PAGE_OFFSET,
  1053. PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) {
  1054. alias_cpa = *cpa;
  1055. alias_cpa.vaddr = &laddr;
  1056. alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
  1057. ret = __change_page_attr_set_clr(&alias_cpa, 0);
  1058. if (ret)
  1059. return ret;
  1060. }
  1061. #ifdef CONFIG_X86_64
  1062. /*
  1063. * If the primary call didn't touch the high mapping already
  1064. * and the physical address is inside the kernel map, we need
  1065. * to touch the high mapped kernel as well:
  1066. */
  1067. if (!within(vaddr, (unsigned long)_text, _brk_end) &&
  1068. within(cpa->pfn, highmap_start_pfn(), highmap_end_pfn())) {
  1069. unsigned long temp_cpa_vaddr = (cpa->pfn << PAGE_SHIFT) +
  1070. __START_KERNEL_map - phys_base;
  1071. alias_cpa = *cpa;
  1072. alias_cpa.vaddr = &temp_cpa_vaddr;
  1073. alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
  1074. /*
  1075. * The high mapping range is imprecise, so ignore the
  1076. * return value.
  1077. */
  1078. __change_page_attr_set_clr(&alias_cpa, 0);
  1079. }
  1080. #endif
  1081. return 0;
  1082. }
  1083. static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
  1084. {
  1085. int ret, numpages = cpa->numpages;
  1086. while (numpages) {
  1087. /*
  1088. * Store the remaining nr of pages for the large page
  1089. * preservation check.
  1090. */
  1091. cpa->numpages = numpages;
  1092. /* for array changes, we can't use large page */
  1093. if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY))
  1094. cpa->numpages = 1;
  1095. if (!debug_pagealloc)
  1096. spin_lock(&cpa_lock);
  1097. ret = __change_page_attr(cpa, checkalias);
  1098. if (!debug_pagealloc)
  1099. spin_unlock(&cpa_lock);
  1100. if (ret)
  1101. return ret;
  1102. if (checkalias) {
  1103. ret = cpa_process_alias(cpa);
  1104. if (ret)
  1105. return ret;
  1106. }
  1107. /*
  1108. * Adjust the number of pages with the result of the
  1109. * CPA operation. Either a large page has been
  1110. * preserved or a single page update happened.
  1111. */
  1112. BUG_ON(cpa->numpages > numpages);
  1113. numpages -= cpa->numpages;
  1114. if (cpa->flags & (CPA_PAGES_ARRAY | CPA_ARRAY))
  1115. cpa->curpage++;
  1116. else
  1117. *cpa->vaddr += cpa->numpages * PAGE_SIZE;
  1118. }
  1119. return 0;
  1120. }
  1121. static int change_page_attr_set_clr(unsigned long *addr, int numpages,
  1122. pgprot_t mask_set, pgprot_t mask_clr,
  1123. int force_split, int in_flag,
  1124. struct page **pages)
  1125. {
  1126. struct cpa_data cpa;
  1127. int ret, cache, checkalias;
  1128. unsigned long baddr = 0;
  1129. memset(&cpa, 0, sizeof(cpa));
  1130. /*
  1131. * Check, if we are requested to change a not supported
  1132. * feature:
  1133. */
  1134. mask_set = canon_pgprot(mask_set);
  1135. mask_clr = canon_pgprot(mask_clr);
  1136. if (!pgprot_val(mask_set) && !pgprot_val(mask_clr) && !force_split)
  1137. return 0;
  1138. /* Ensure we are PAGE_SIZE aligned */
  1139. if (in_flag & CPA_ARRAY) {
  1140. int i;
  1141. for (i = 0; i < numpages; i++) {
  1142. if (addr[i] & ~PAGE_MASK) {
  1143. addr[i] &= PAGE_MASK;
  1144. WARN_ON_ONCE(1);
  1145. }
  1146. }
  1147. } else if (!(in_flag & CPA_PAGES_ARRAY)) {
  1148. /*
  1149. * in_flag of CPA_PAGES_ARRAY implies it is aligned.
  1150. * No need to cehck in that case
  1151. */
  1152. if (*addr & ~PAGE_MASK) {
  1153. *addr &= PAGE_MASK;
  1154. /*
  1155. * People should not be passing in unaligned addresses:
  1156. */
  1157. WARN_ON_ONCE(1);
  1158. }
  1159. /*
  1160. * Save address for cache flush. *addr is modified in the call
  1161. * to __change_page_attr_set_clr() below.
  1162. */
  1163. baddr = *addr;
  1164. }
  1165. /* Must avoid aliasing mappings in the highmem code */
  1166. kmap_flush_unused();
  1167. vm_unmap_aliases();
  1168. cpa.vaddr = addr;
  1169. cpa.pages = pages;
  1170. cpa.numpages = numpages;
  1171. cpa.mask_set = mask_set;
  1172. cpa.mask_clr = mask_clr;
  1173. cpa.flags = 0;
  1174. cpa.curpage = 0;
  1175. cpa.force_split = force_split;
  1176. if (in_flag & (CPA_ARRAY | CPA_PAGES_ARRAY))
  1177. cpa.flags |= in_flag;
  1178. /* No alias checking for _NX bit modifications */
  1179. checkalias = (pgprot_val(mask_set) | pgprot_val(mask_clr)) != _PAGE_NX;
  1180. ret = __change_page_attr_set_clr(&cpa, checkalias);
  1181. /*
  1182. * Check whether we really changed something:
  1183. */
  1184. if (!(cpa.flags & CPA_FLUSHTLB))
  1185. goto out;
  1186. /*
  1187. * No need to flush, when we did not set any of the caching
  1188. * attributes:
  1189. */
  1190. cache = !!pgprot2cachemode(mask_set);
  1191. /*
  1192. * On success we use CLFLUSH, when the CPU supports it to
  1193. * avoid the WBINVD. If the CPU does not support it and in the
  1194. * error case we fall back to cpa_flush_all (which uses
  1195. * WBINVD):
  1196. */
  1197. if (!ret && cpu_has_clflush) {
  1198. if (cpa.flags & (CPA_PAGES_ARRAY | CPA_ARRAY)) {
  1199. cpa_flush_array(addr, numpages, cache,
  1200. cpa.flags, pages);
  1201. } else
  1202. cpa_flush_range(baddr, numpages, cache);
  1203. } else
  1204. cpa_flush_all(cache);
  1205. out:
  1206. return ret;
  1207. }
  1208. static inline int change_page_attr_set(unsigned long *addr, int numpages,
  1209. pgprot_t mask, int array)
  1210. {
  1211. return change_page_attr_set_clr(addr, numpages, mask, __pgprot(0), 0,
  1212. (array ? CPA_ARRAY : 0), NULL);
  1213. }
  1214. static inline int change_page_attr_clear(unsigned long *addr, int numpages,
  1215. pgprot_t mask, int array)
  1216. {
  1217. return change_page_attr_set_clr(addr, numpages, __pgprot(0), mask, 0,
  1218. (array ? CPA_ARRAY : 0), NULL);
  1219. }
  1220. static inline int cpa_set_pages_array(struct page **pages, int numpages,
  1221. pgprot_t mask)
  1222. {
  1223. return change_page_attr_set_clr(NULL, numpages, mask, __pgprot(0), 0,
  1224. CPA_PAGES_ARRAY, pages);
  1225. }
  1226. static inline int cpa_clear_pages_array(struct page **pages, int numpages,
  1227. pgprot_t mask)
  1228. {
  1229. return change_page_attr_set_clr(NULL, numpages, __pgprot(0), mask, 0,
  1230. CPA_PAGES_ARRAY, pages);
  1231. }
  1232. int _set_memory_uc(unsigned long addr, int numpages)
  1233. {
  1234. /*
  1235. * for now UC MINUS. see comments in ioremap_nocache()
  1236. * If you really need strong UC use ioremap_uc(), but note
  1237. * that you cannot override IO areas with set_memory_*() as
  1238. * these helpers cannot work with IO memory.
  1239. */
  1240. return change_page_attr_set(&addr, numpages,
  1241. cachemode2pgprot(_PAGE_CACHE_MODE_UC_MINUS),
  1242. 0);
  1243. }
  1244. int set_memory_uc(unsigned long addr, int numpages)
  1245. {
  1246. int ret;
  1247. /*
  1248. * for now UC MINUS. see comments in ioremap_nocache()
  1249. */
  1250. ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
  1251. _PAGE_CACHE_MODE_UC_MINUS, NULL);
  1252. if (ret)
  1253. goto out_err;
  1254. ret = _set_memory_uc(addr, numpages);
  1255. if (ret)
  1256. goto out_free;
  1257. return 0;
  1258. out_free:
  1259. free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
  1260. out_err:
  1261. return ret;
  1262. }
  1263. EXPORT_SYMBOL(set_memory_uc);
  1264. static int _set_memory_array(unsigned long *addr, int addrinarray,
  1265. enum page_cache_mode new_type)
  1266. {
  1267. enum page_cache_mode set_type;
  1268. int i, j;
  1269. int ret;
  1270. for (i = 0; i < addrinarray; i++) {
  1271. ret = reserve_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE,
  1272. new_type, NULL);
  1273. if (ret)
  1274. goto out_free;
  1275. }
  1276. /* If WC, set to UC- first and then WC */
  1277. set_type = (new_type == _PAGE_CACHE_MODE_WC) ?
  1278. _PAGE_CACHE_MODE_UC_MINUS : new_type;
  1279. ret = change_page_attr_set(addr, addrinarray,
  1280. cachemode2pgprot(set_type), 1);
  1281. if (!ret && new_type == _PAGE_CACHE_MODE_WC)
  1282. ret = change_page_attr_set_clr(addr, addrinarray,
  1283. cachemode2pgprot(
  1284. _PAGE_CACHE_MODE_WC),
  1285. __pgprot(_PAGE_CACHE_MASK),
  1286. 0, CPA_ARRAY, NULL);
  1287. if (ret)
  1288. goto out_free;
  1289. return 0;
  1290. out_free:
  1291. for (j = 0; j < i; j++)
  1292. free_memtype(__pa(addr[j]), __pa(addr[j]) + PAGE_SIZE);
  1293. return ret;
  1294. }
  1295. int set_memory_array_uc(unsigned long *addr, int addrinarray)
  1296. {
  1297. return _set_memory_array(addr, addrinarray, _PAGE_CACHE_MODE_UC_MINUS);
  1298. }
  1299. EXPORT_SYMBOL(set_memory_array_uc);
  1300. int set_memory_array_wc(unsigned long *addr, int addrinarray)
  1301. {
  1302. return _set_memory_array(addr, addrinarray, _PAGE_CACHE_MODE_WC);
  1303. }
  1304. EXPORT_SYMBOL(set_memory_array_wc);
  1305. int set_memory_array_wt(unsigned long *addr, int addrinarray)
  1306. {
  1307. return _set_memory_array(addr, addrinarray, _PAGE_CACHE_MODE_WT);
  1308. }
  1309. EXPORT_SYMBOL_GPL(set_memory_array_wt);
  1310. int _set_memory_wc(unsigned long addr, int numpages)
  1311. {
  1312. int ret;
  1313. unsigned long addr_copy = addr;
  1314. ret = change_page_attr_set(&addr, numpages,
  1315. cachemode2pgprot(_PAGE_CACHE_MODE_UC_MINUS),
  1316. 0);
  1317. if (!ret) {
  1318. ret = change_page_attr_set_clr(&addr_copy, numpages,
  1319. cachemode2pgprot(
  1320. _PAGE_CACHE_MODE_WC),
  1321. __pgprot(_PAGE_CACHE_MASK),
  1322. 0, 0, NULL);
  1323. }
  1324. return ret;
  1325. }
  1326. int set_memory_wc(unsigned long addr, int numpages)
  1327. {
  1328. int ret;
  1329. ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
  1330. _PAGE_CACHE_MODE_WC, NULL);
  1331. if (ret)
  1332. return ret;
  1333. ret = _set_memory_wc(addr, numpages);
  1334. if (ret)
  1335. free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
  1336. return ret;
  1337. }
  1338. EXPORT_SYMBOL(set_memory_wc);
  1339. int _set_memory_wt(unsigned long addr, int numpages)
  1340. {
  1341. return change_page_attr_set(&addr, numpages,
  1342. cachemode2pgprot(_PAGE_CACHE_MODE_WT), 0);
  1343. }
  1344. int set_memory_wt(unsigned long addr, int numpages)
  1345. {
  1346. int ret;
  1347. ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
  1348. _PAGE_CACHE_MODE_WT, NULL);
  1349. if (ret)
  1350. return ret;
  1351. ret = _set_memory_wt(addr, numpages);
  1352. if (ret)
  1353. free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
  1354. return ret;
  1355. }
  1356. EXPORT_SYMBOL_GPL(set_memory_wt);
  1357. int _set_memory_wb(unsigned long addr, int numpages)
  1358. {
  1359. /* WB cache mode is hard wired to all cache attribute bits being 0 */
  1360. return change_page_attr_clear(&addr, numpages,
  1361. __pgprot(_PAGE_CACHE_MASK), 0);
  1362. }
  1363. int set_memory_wb(unsigned long addr, int numpages)
  1364. {
  1365. int ret;
  1366. ret = _set_memory_wb(addr, numpages);
  1367. if (ret)
  1368. return ret;
  1369. free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
  1370. return 0;
  1371. }
  1372. EXPORT_SYMBOL(set_memory_wb);
  1373. int set_memory_array_wb(unsigned long *addr, int addrinarray)
  1374. {
  1375. int i;
  1376. int ret;
  1377. /* WB cache mode is hard wired to all cache attribute bits being 0 */
  1378. ret = change_page_attr_clear(addr, addrinarray,
  1379. __pgprot(_PAGE_CACHE_MASK), 1);
  1380. if (ret)
  1381. return ret;
  1382. for (i = 0; i < addrinarray; i++)
  1383. free_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE);
  1384. return 0;
  1385. }
  1386. EXPORT_SYMBOL(set_memory_array_wb);
  1387. int set_memory_x(unsigned long addr, int numpages)
  1388. {
  1389. if (!(__supported_pte_mask & _PAGE_NX))
  1390. return 0;
  1391. return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_NX), 0);
  1392. }
  1393. EXPORT_SYMBOL(set_memory_x);
  1394. int set_memory_nx(unsigned long addr, int numpages)
  1395. {
  1396. if (!(__supported_pte_mask & _PAGE_NX))
  1397. return 0;
  1398. return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_NX), 0);
  1399. }
  1400. EXPORT_SYMBOL(set_memory_nx);
  1401. int set_memory_ro(unsigned long addr, int numpages)
  1402. {
  1403. return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0);
  1404. }
  1405. int set_memory_rw(unsigned long addr, int numpages)
  1406. {
  1407. return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_RW), 0);
  1408. }
  1409. int set_memory_np(unsigned long addr, int numpages)
  1410. {
  1411. return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_PRESENT), 0);
  1412. }
  1413. int set_memory_4k(unsigned long addr, int numpages)
  1414. {
  1415. return change_page_attr_set_clr(&addr, numpages, __pgprot(0),
  1416. __pgprot(0), 1, 0, NULL);
  1417. }
  1418. int set_pages_uc(struct page *page, int numpages)
  1419. {
  1420. unsigned long addr = (unsigned long)page_address(page);
  1421. return set_memory_uc(addr, numpages);
  1422. }
  1423. EXPORT_SYMBOL(set_pages_uc);
  1424. static int _set_pages_array(struct page **pages, int addrinarray,
  1425. enum page_cache_mode new_type)
  1426. {
  1427. unsigned long start;
  1428. unsigned long end;
  1429. enum page_cache_mode set_type;
  1430. int i;
  1431. int free_idx;
  1432. int ret;
  1433. for (i = 0; i < addrinarray; i++) {
  1434. if (PageHighMem(pages[i]))
  1435. continue;
  1436. start = page_to_pfn(pages[i]) << PAGE_SHIFT;
  1437. end = start + PAGE_SIZE;
  1438. if (reserve_memtype(start, end, new_type, NULL))
  1439. goto err_out;
  1440. }
  1441. /* If WC, set to UC- first and then WC */
  1442. set_type = (new_type == _PAGE_CACHE_MODE_WC) ?
  1443. _PAGE_CACHE_MODE_UC_MINUS : new_type;
  1444. ret = cpa_set_pages_array(pages, addrinarray,
  1445. cachemode2pgprot(set_type));
  1446. if (!ret && new_type == _PAGE_CACHE_MODE_WC)
  1447. ret = change_page_attr_set_clr(NULL, addrinarray,
  1448. cachemode2pgprot(
  1449. _PAGE_CACHE_MODE_WC),
  1450. __pgprot(_PAGE_CACHE_MASK),
  1451. 0, CPA_PAGES_ARRAY, pages);
  1452. if (ret)
  1453. goto err_out;
  1454. return 0; /* Success */
  1455. err_out:
  1456. free_idx = i;
  1457. for (i = 0; i < free_idx; i++) {
  1458. if (PageHighMem(pages[i]))
  1459. continue;
  1460. start = page_to_pfn(pages[i]) << PAGE_SHIFT;
  1461. end = start + PAGE_SIZE;
  1462. free_memtype(start, end);
  1463. }
  1464. return -EINVAL;
  1465. }
  1466. int set_pages_array_uc(struct page **pages, int addrinarray)
  1467. {
  1468. return _set_pages_array(pages, addrinarray, _PAGE_CACHE_MODE_UC_MINUS);
  1469. }
  1470. EXPORT_SYMBOL(set_pages_array_uc);
  1471. int set_pages_array_wc(struct page **pages, int addrinarray)
  1472. {
  1473. return _set_pages_array(pages, addrinarray, _PAGE_CACHE_MODE_WC);
  1474. }
  1475. EXPORT_SYMBOL(set_pages_array_wc);
  1476. int set_pages_array_wt(struct page **pages, int addrinarray)
  1477. {
  1478. return _set_pages_array(pages, addrinarray, _PAGE_CACHE_MODE_WT);
  1479. }
  1480. EXPORT_SYMBOL_GPL(set_pages_array_wt);
  1481. int set_pages_wb(struct page *page, int numpages)
  1482. {
  1483. unsigned long addr = (unsigned long)page_address(page);
  1484. return set_memory_wb(addr, numpages);
  1485. }
  1486. EXPORT_SYMBOL(set_pages_wb);
  1487. int set_pages_array_wb(struct page **pages, int addrinarray)
  1488. {
  1489. int retval;
  1490. unsigned long start;
  1491. unsigned long end;
  1492. int i;
  1493. /* WB cache mode is hard wired to all cache attribute bits being 0 */
  1494. retval = cpa_clear_pages_array(pages, addrinarray,
  1495. __pgprot(_PAGE_CACHE_MASK));
  1496. if (retval)
  1497. return retval;
  1498. for (i = 0; i < addrinarray; i++) {
  1499. if (PageHighMem(pages[i]))
  1500. continue;
  1501. start = page_to_pfn(pages[i]) << PAGE_SHIFT;
  1502. end = start + PAGE_SIZE;
  1503. free_memtype(start, end);
  1504. }
  1505. return 0;
  1506. }
  1507. EXPORT_SYMBOL(set_pages_array_wb);
  1508. int set_pages_x(struct page *page, int numpages)
  1509. {
  1510. unsigned long addr = (unsigned long)page_address(page);
  1511. return set_memory_x(addr, numpages);
  1512. }
  1513. EXPORT_SYMBOL(set_pages_x);
  1514. int set_pages_nx(struct page *page, int numpages)
  1515. {
  1516. unsigned long addr = (unsigned long)page_address(page);
  1517. return set_memory_nx(addr, numpages);
  1518. }
  1519. EXPORT_SYMBOL(set_pages_nx);
  1520. int set_pages_ro(struct page *page, int numpages)
  1521. {
  1522. unsigned long addr = (unsigned long)page_address(page);
  1523. return set_memory_ro(addr, numpages);
  1524. }
  1525. int set_pages_rw(struct page *page, int numpages)
  1526. {
  1527. unsigned long addr = (unsigned long)page_address(page);
  1528. return set_memory_rw(addr, numpages);
  1529. }
  1530. #ifdef CONFIG_DEBUG_PAGEALLOC
  1531. static int __set_pages_p(struct page *page, int numpages)
  1532. {
  1533. unsigned long tempaddr = (unsigned long) page_address(page);
  1534. struct cpa_data cpa = { .vaddr = &tempaddr,
  1535. .pgd = NULL,
  1536. .numpages = numpages,
  1537. .mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW),
  1538. .mask_clr = __pgprot(0),
  1539. .flags = 0};
  1540. /*
  1541. * No alias checking needed for setting present flag. otherwise,
  1542. * we may need to break large pages for 64-bit kernel text
  1543. * mappings (this adds to complexity if we want to do this from
  1544. * atomic context especially). Let's keep it simple!
  1545. */
  1546. return __change_page_attr_set_clr(&cpa, 0);
  1547. }
  1548. static int __set_pages_np(struct page *page, int numpages)
  1549. {
  1550. unsigned long tempaddr = (unsigned long) page_address(page);
  1551. struct cpa_data cpa = { .vaddr = &tempaddr,
  1552. .pgd = NULL,
  1553. .numpages = numpages,
  1554. .mask_set = __pgprot(0),
  1555. .mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW),
  1556. .flags = 0};
  1557. /*
  1558. * No alias checking needed for setting not present flag. otherwise,
  1559. * we may need to break large pages for 64-bit kernel text
  1560. * mappings (this adds to complexity if we want to do this from
  1561. * atomic context especially). Let's keep it simple!
  1562. */
  1563. return __change_page_attr_set_clr(&cpa, 0);
  1564. }
  1565. void __kernel_map_pages(struct page *page, int numpages, int enable)
  1566. {
  1567. if (PageHighMem(page))
  1568. return;
  1569. if (!enable) {
  1570. debug_check_no_locks_freed(page_address(page),
  1571. numpages * PAGE_SIZE);
  1572. }
  1573. /*
  1574. * The return value is ignored as the calls cannot fail.
  1575. * Large pages for identity mappings are not used at boot time
  1576. * and hence no memory allocations during large page split.
  1577. */
  1578. if (enable)
  1579. __set_pages_p(page, numpages);
  1580. else
  1581. __set_pages_np(page, numpages);
  1582. /*
  1583. * We should perform an IPI and flush all tlbs,
  1584. * but that can deadlock->flush only current cpu:
  1585. */
  1586. __flush_tlb_all();
  1587. arch_flush_lazy_mmu_mode();
  1588. }
  1589. #ifdef CONFIG_HIBERNATION
  1590. bool kernel_page_present(struct page *page)
  1591. {
  1592. unsigned int level;
  1593. pte_t *pte;
  1594. if (PageHighMem(page))
  1595. return false;
  1596. pte = lookup_address((unsigned long)page_address(page), &level);
  1597. return (pte_val(*pte) & _PAGE_PRESENT);
  1598. }
  1599. #endif /* CONFIG_HIBERNATION */
  1600. #endif /* CONFIG_DEBUG_PAGEALLOC */
  1601. int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
  1602. unsigned numpages, unsigned long page_flags)
  1603. {
  1604. int retval = -EINVAL;
  1605. struct cpa_data cpa = {
  1606. .vaddr = &address,
  1607. .pfn = pfn,
  1608. .pgd = pgd,
  1609. .numpages = numpages,
  1610. .mask_set = __pgprot(0),
  1611. .mask_clr = __pgprot(0),
  1612. .flags = 0,
  1613. };
  1614. if (!(__supported_pte_mask & _PAGE_NX))
  1615. goto out;
  1616. if (!(page_flags & _PAGE_NX))
  1617. cpa.mask_clr = __pgprot(_PAGE_NX);
  1618. cpa.mask_set = __pgprot(_PAGE_PRESENT | page_flags);
  1619. retval = __change_page_attr_set_clr(&cpa, 0);
  1620. __flush_tlb_all();
  1621. out:
  1622. return retval;
  1623. }
  1624. void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
  1625. unsigned numpages)
  1626. {
  1627. unmap_pgd_range(root, address, address + (numpages << PAGE_SHIFT));
  1628. }
  1629. /*
  1630. * The testcases use internal knowledge of the implementation that shouldn't
  1631. * be exposed to the rest of the kernel. Include these directly here.
  1632. */
  1633. #ifdef CONFIG_CPA_DEBUG
  1634. #include "pageattr-test.c"
  1635. #endif