pageattr.c 47 KB

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