pgtable.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #include <linux/mm.h>
  2. #include <linux/gfp.h>
  3. #include <asm/pgalloc.h>
  4. #include <asm/pgtable.h>
  5. #include <asm/tlb.h>
  6. #include <asm/fixmap.h>
  7. #include <asm/mtrr.h>
  8. #define PGALLOC_GFP GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO
  9. #ifdef CONFIG_HIGHPTE
  10. #define PGALLOC_USER_GFP __GFP_HIGHMEM
  11. #else
  12. #define PGALLOC_USER_GFP 0
  13. #endif
  14. gfp_t __userpte_alloc_gfp = PGALLOC_GFP | PGALLOC_USER_GFP;
  15. pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  16. {
  17. return (pte_t *)__get_free_page(PGALLOC_GFP);
  18. }
  19. pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
  20. {
  21. struct page *pte;
  22. pte = alloc_pages(__userpte_alloc_gfp, 0);
  23. if (!pte)
  24. return NULL;
  25. if (!pgtable_page_ctor(pte)) {
  26. __free_page(pte);
  27. return NULL;
  28. }
  29. return pte;
  30. }
  31. static int __init setup_userpte(char *arg)
  32. {
  33. if (!arg)
  34. return -EINVAL;
  35. /*
  36. * "userpte=nohigh" disables allocation of user pagetables in
  37. * high memory.
  38. */
  39. if (strcmp(arg, "nohigh") == 0)
  40. __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
  41. else
  42. return -EINVAL;
  43. return 0;
  44. }
  45. early_param("userpte", setup_userpte);
  46. void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
  47. {
  48. pgtable_page_dtor(pte);
  49. paravirt_release_pte(page_to_pfn(pte));
  50. tlb_remove_page(tlb, pte);
  51. }
  52. #if CONFIG_PGTABLE_LEVELS > 2
  53. void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
  54. {
  55. struct page *page = virt_to_page(pmd);
  56. paravirt_release_pmd(__pa(pmd) >> PAGE_SHIFT);
  57. /*
  58. * NOTE! For PAE, any changes to the top page-directory-pointer-table
  59. * entries need a full cr3 reload to flush.
  60. */
  61. #ifdef CONFIG_X86_PAE
  62. tlb->need_flush_all = 1;
  63. #endif
  64. pgtable_pmd_page_dtor(page);
  65. tlb_remove_page(tlb, page);
  66. }
  67. #if CONFIG_PGTABLE_LEVELS > 3
  68. void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud)
  69. {
  70. paravirt_release_pud(__pa(pud) >> PAGE_SHIFT);
  71. tlb_remove_page(tlb, virt_to_page(pud));
  72. }
  73. #endif /* CONFIG_PGTABLE_LEVELS > 3 */
  74. #endif /* CONFIG_PGTABLE_LEVELS > 2 */
  75. static inline void pgd_list_add(pgd_t *pgd)
  76. {
  77. struct page *page = virt_to_page(pgd);
  78. list_add(&page->lru, &pgd_list);
  79. }
  80. static inline void pgd_list_del(pgd_t *pgd)
  81. {
  82. struct page *page = virt_to_page(pgd);
  83. list_del(&page->lru);
  84. }
  85. #define UNSHARED_PTRS_PER_PGD \
  86. (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
  87. static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
  88. {
  89. BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
  90. virt_to_page(pgd)->index = (pgoff_t)mm;
  91. }
  92. struct mm_struct *pgd_page_get_mm(struct page *page)
  93. {
  94. return (struct mm_struct *)page->index;
  95. }
  96. static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd)
  97. {
  98. /* If the pgd points to a shared pagetable level (either the
  99. ptes in non-PAE, or shared PMD in PAE), then just copy the
  100. references from swapper_pg_dir. */
  101. if (CONFIG_PGTABLE_LEVELS == 2 ||
  102. (CONFIG_PGTABLE_LEVELS == 3 && SHARED_KERNEL_PMD) ||
  103. CONFIG_PGTABLE_LEVELS == 4) {
  104. clone_pgd_range(pgd + KERNEL_PGD_BOUNDARY,
  105. swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  106. KERNEL_PGD_PTRS);
  107. }
  108. /* list required to sync kernel mapping updates */
  109. if (!SHARED_KERNEL_PMD) {
  110. pgd_set_mm(pgd, mm);
  111. pgd_list_add(pgd);
  112. }
  113. }
  114. static void pgd_dtor(pgd_t *pgd)
  115. {
  116. if (SHARED_KERNEL_PMD)
  117. return;
  118. spin_lock(&pgd_lock);
  119. pgd_list_del(pgd);
  120. spin_unlock(&pgd_lock);
  121. }
  122. /*
  123. * List of all pgd's needed for non-PAE so it can invalidate entries
  124. * in both cached and uncached pgd's; not needed for PAE since the
  125. * kernel pmd is shared. If PAE were not to share the pmd a similar
  126. * tactic would be needed. This is essentially codepath-based locking
  127. * against pageattr.c; it is the unique case in which a valid change
  128. * of kernel pagetables can't be lazily synchronized by vmalloc faults.
  129. * vmalloc faults work because attached pagetables are never freed.
  130. * -- nyc
  131. */
  132. #ifdef CONFIG_X86_PAE
  133. /*
  134. * In PAE mode, we need to do a cr3 reload (=tlb flush) when
  135. * updating the top-level pagetable entries to guarantee the
  136. * processor notices the update. Since this is expensive, and
  137. * all 4 top-level entries are used almost immediately in a
  138. * new process's life, we just pre-populate them here.
  139. *
  140. * Also, if we're in a paravirt environment where the kernel pmd is
  141. * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
  142. * and initialize the kernel pmds here.
  143. */
  144. #define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
  145. void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
  146. {
  147. paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
  148. /* Note: almost everything apart from _PAGE_PRESENT is
  149. reserved at the pmd (PDPT) level. */
  150. set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
  151. /*
  152. * According to Intel App note "TLBs, Paging-Structure Caches,
  153. * and Their Invalidation", April 2007, document 317080-001,
  154. * section 8.1: in PAE mode we explicitly have to flush the
  155. * TLB via cr3 if the top-level pgd is changed...
  156. */
  157. flush_tlb_mm(mm);
  158. }
  159. #else /* !CONFIG_X86_PAE */
  160. /* No need to prepopulate any pagetable entries in non-PAE modes. */
  161. #define PREALLOCATED_PMDS 0
  162. #endif /* CONFIG_X86_PAE */
  163. static void free_pmds(struct mm_struct *mm, pmd_t *pmds[])
  164. {
  165. int i;
  166. for(i = 0; i < PREALLOCATED_PMDS; i++)
  167. if (pmds[i]) {
  168. pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
  169. free_page((unsigned long)pmds[i]);
  170. mm_dec_nr_pmds(mm);
  171. }
  172. }
  173. static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[])
  174. {
  175. int i;
  176. bool failed = false;
  177. for(i = 0; i < PREALLOCATED_PMDS; i++) {
  178. pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
  179. if (!pmd)
  180. failed = true;
  181. if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
  182. free_page((unsigned long)pmd);
  183. pmd = NULL;
  184. failed = true;
  185. }
  186. if (pmd)
  187. mm_inc_nr_pmds(mm);
  188. pmds[i] = pmd;
  189. }
  190. if (failed) {
  191. free_pmds(mm, pmds);
  192. return -ENOMEM;
  193. }
  194. return 0;
  195. }
  196. /*
  197. * Mop up any pmd pages which may still be attached to the pgd.
  198. * Normally they will be freed by munmap/exit_mmap, but any pmd we
  199. * preallocate which never got a corresponding vma will need to be
  200. * freed manually.
  201. */
  202. static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
  203. {
  204. int i;
  205. for(i = 0; i < PREALLOCATED_PMDS; i++) {
  206. pgd_t pgd = pgdp[i];
  207. if (pgd_val(pgd) != 0) {
  208. pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
  209. pgdp[i] = native_make_pgd(0);
  210. paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
  211. pmd_free(mm, pmd);
  212. mm_dec_nr_pmds(mm);
  213. }
  214. }
  215. }
  216. static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
  217. {
  218. pud_t *pud;
  219. int i;
  220. if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
  221. return;
  222. pud = pud_offset(pgd, 0);
  223. for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
  224. pmd_t *pmd = pmds[i];
  225. if (i >= KERNEL_PGD_BOUNDARY)
  226. memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
  227. sizeof(pmd_t) * PTRS_PER_PMD);
  228. pud_populate(mm, pud, pmd);
  229. }
  230. }
  231. /*
  232. * Xen paravirt assumes pgd table should be in one page. 64 bit kernel also
  233. * assumes that pgd should be in one page.
  234. *
  235. * But kernel with PAE paging that is not running as a Xen domain
  236. * only needs to allocate 32 bytes for pgd instead of one page.
  237. */
  238. #ifdef CONFIG_X86_PAE
  239. #include <linux/slab.h>
  240. #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  241. #define PGD_ALIGN 32
  242. static struct kmem_cache *pgd_cache;
  243. static int __init pgd_cache_init(void)
  244. {
  245. /*
  246. * When PAE kernel is running as a Xen domain, it does not use
  247. * shared kernel pmd. And this requires a whole page for pgd.
  248. */
  249. if (!SHARED_KERNEL_PMD)
  250. return 0;
  251. /*
  252. * when PAE kernel is not running as a Xen domain, it uses
  253. * shared kernel pmd. Shared kernel pmd does not require a whole
  254. * page for pgd. We are able to just allocate a 32-byte for pgd.
  255. * During boot time, we create a 32-byte slab for pgd table allocation.
  256. */
  257. pgd_cache = kmem_cache_create("pgd_cache", PGD_SIZE, PGD_ALIGN,
  258. SLAB_PANIC, NULL);
  259. if (!pgd_cache)
  260. return -ENOMEM;
  261. return 0;
  262. }
  263. core_initcall(pgd_cache_init);
  264. static inline pgd_t *_pgd_alloc(void)
  265. {
  266. /*
  267. * If no SHARED_KERNEL_PMD, PAE kernel is running as a Xen domain.
  268. * We allocate one page for pgd.
  269. */
  270. if (!SHARED_KERNEL_PMD)
  271. return (pgd_t *)__get_free_page(PGALLOC_GFP);
  272. /*
  273. * Now PAE kernel is not running as a Xen domain. We can allocate
  274. * a 32-byte slab for pgd to save memory space.
  275. */
  276. return kmem_cache_alloc(pgd_cache, PGALLOC_GFP);
  277. }
  278. static inline void _pgd_free(pgd_t *pgd)
  279. {
  280. if (!SHARED_KERNEL_PMD)
  281. free_page((unsigned long)pgd);
  282. else
  283. kmem_cache_free(pgd_cache, pgd);
  284. }
  285. #else
  286. static inline pgd_t *_pgd_alloc(void)
  287. {
  288. return (pgd_t *)__get_free_page(PGALLOC_GFP);
  289. }
  290. static inline void _pgd_free(pgd_t *pgd)
  291. {
  292. free_page((unsigned long)pgd);
  293. }
  294. #endif /* CONFIG_X86_PAE */
  295. pgd_t *pgd_alloc(struct mm_struct *mm)
  296. {
  297. pgd_t *pgd;
  298. pmd_t *pmds[PREALLOCATED_PMDS];
  299. pgd = _pgd_alloc();
  300. if (pgd == NULL)
  301. goto out;
  302. mm->pgd = pgd;
  303. if (preallocate_pmds(mm, pmds) != 0)
  304. goto out_free_pgd;
  305. if (paravirt_pgd_alloc(mm) != 0)
  306. goto out_free_pmds;
  307. /*
  308. * Make sure that pre-populating the pmds is atomic with
  309. * respect to anything walking the pgd_list, so that they
  310. * never see a partially populated pgd.
  311. */
  312. spin_lock(&pgd_lock);
  313. pgd_ctor(mm, pgd);
  314. pgd_prepopulate_pmd(mm, pgd, pmds);
  315. spin_unlock(&pgd_lock);
  316. return pgd;
  317. out_free_pmds:
  318. free_pmds(mm, pmds);
  319. out_free_pgd:
  320. _pgd_free(pgd);
  321. out:
  322. return NULL;
  323. }
  324. void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  325. {
  326. pgd_mop_up_pmds(mm, pgd);
  327. pgd_dtor(pgd);
  328. paravirt_pgd_free(mm, pgd);
  329. _pgd_free(pgd);
  330. }
  331. /*
  332. * Used to set accessed or dirty bits in the page table entries
  333. * on other architectures. On x86, the accessed and dirty bits
  334. * are tracked by hardware. However, do_wp_page calls this function
  335. * to also make the pte writeable at the same time the dirty bit is
  336. * set. In that case we do actually need to write the PTE.
  337. */
  338. int ptep_set_access_flags(struct vm_area_struct *vma,
  339. unsigned long address, pte_t *ptep,
  340. pte_t entry, int dirty)
  341. {
  342. int changed = !pte_same(*ptep, entry);
  343. if (changed && dirty) {
  344. *ptep = entry;
  345. pte_update_defer(vma->vm_mm, address, ptep);
  346. }
  347. return changed;
  348. }
  349. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  350. int pmdp_set_access_flags(struct vm_area_struct *vma,
  351. unsigned long address, pmd_t *pmdp,
  352. pmd_t entry, int dirty)
  353. {
  354. int changed = !pmd_same(*pmdp, entry);
  355. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  356. if (changed && dirty) {
  357. *pmdp = entry;
  358. pmd_update_defer(vma->vm_mm, address, pmdp);
  359. /*
  360. * We had a write-protection fault here and changed the pmd
  361. * to to more permissive. No need to flush the TLB for that,
  362. * #PF is architecturally guaranteed to do that and in the
  363. * worst-case we'll generate a spurious fault.
  364. */
  365. }
  366. return changed;
  367. }
  368. #endif
  369. int ptep_test_and_clear_young(struct vm_area_struct *vma,
  370. unsigned long addr, pte_t *ptep)
  371. {
  372. int ret = 0;
  373. if (pte_young(*ptep))
  374. ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
  375. (unsigned long *) &ptep->pte);
  376. if (ret)
  377. pte_update(vma->vm_mm, addr, ptep);
  378. return ret;
  379. }
  380. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  381. int pmdp_test_and_clear_young(struct vm_area_struct *vma,
  382. unsigned long addr, pmd_t *pmdp)
  383. {
  384. int ret = 0;
  385. if (pmd_young(*pmdp))
  386. ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
  387. (unsigned long *)pmdp);
  388. if (ret)
  389. pmd_update(vma->vm_mm, addr, pmdp);
  390. return ret;
  391. }
  392. #endif
  393. int ptep_clear_flush_young(struct vm_area_struct *vma,
  394. unsigned long address, pte_t *ptep)
  395. {
  396. /*
  397. * On x86 CPUs, clearing the accessed bit without a TLB flush
  398. * doesn't cause data corruption. [ It could cause incorrect
  399. * page aging and the (mistaken) reclaim of hot pages, but the
  400. * chance of that should be relatively low. ]
  401. *
  402. * So as a performance optimization don't flush the TLB when
  403. * clearing the accessed bit, it will eventually be flushed by
  404. * a context switch or a VM operation anyway. [ In the rare
  405. * event of it not getting flushed for a long time the delay
  406. * shouldn't really matter because there's no real memory
  407. * pressure for swapout to react to. ]
  408. */
  409. return ptep_test_and_clear_young(vma, address, ptep);
  410. }
  411. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  412. int pmdp_clear_flush_young(struct vm_area_struct *vma,
  413. unsigned long address, pmd_t *pmdp)
  414. {
  415. int young;
  416. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  417. young = pmdp_test_and_clear_young(vma, address, pmdp);
  418. if (young)
  419. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  420. return young;
  421. }
  422. void pmdp_splitting_flush(struct vm_area_struct *vma,
  423. unsigned long address, pmd_t *pmdp)
  424. {
  425. int set;
  426. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  427. set = !test_and_set_bit(_PAGE_BIT_SPLITTING,
  428. (unsigned long *)pmdp);
  429. if (set) {
  430. pmd_update(vma->vm_mm, address, pmdp);
  431. /* need tlb flush only to serialize against gup-fast */
  432. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  433. }
  434. }
  435. #endif
  436. /**
  437. * reserve_top_address - reserves a hole in the top of kernel address space
  438. * @reserve - size of hole to reserve
  439. *
  440. * Can be used to relocate the fixmap area and poke a hole in the top
  441. * of kernel address space to make room for a hypervisor.
  442. */
  443. void __init reserve_top_address(unsigned long reserve)
  444. {
  445. #ifdef CONFIG_X86_32
  446. BUG_ON(fixmaps_set > 0);
  447. __FIXADDR_TOP = round_down(-reserve, 1 << PMD_SHIFT) - PAGE_SIZE;
  448. printk(KERN_INFO "Reserving virtual address space above 0x%08lx (rounded to 0x%08lx)\n",
  449. -reserve, __FIXADDR_TOP + PAGE_SIZE);
  450. #endif
  451. }
  452. int fixmaps_set;
  453. void __native_set_fixmap(enum fixed_addresses idx, pte_t pte)
  454. {
  455. unsigned long address = __fix_to_virt(idx);
  456. if (idx >= __end_of_fixed_addresses) {
  457. BUG();
  458. return;
  459. }
  460. set_pte_vaddr(address, pte);
  461. fixmaps_set++;
  462. }
  463. void native_set_fixmap(enum fixed_addresses idx, phys_addr_t phys,
  464. pgprot_t flags)
  465. {
  466. __native_set_fixmap(idx, pfn_pte(phys >> PAGE_SHIFT, flags));
  467. }
  468. #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
  469. /**
  470. * pud_set_huge - setup kernel PUD mapping
  471. *
  472. * MTRRs can override PAT memory types with 4KiB granularity. Therefore, this
  473. * function sets up a huge page only if any of the following conditions are met:
  474. *
  475. * - MTRRs are disabled, or
  476. *
  477. * - MTRRs are enabled and the range is completely covered by a single MTRR, or
  478. *
  479. * - MTRRs are enabled and the corresponding MTRR memory type is WB, which
  480. * has no effect on the requested PAT memory type.
  481. *
  482. * Callers should try to decrease page size (1GB -> 2MB -> 4K) if the bigger
  483. * page mapping attempt fails.
  484. *
  485. * Returns 1 on success and 0 on failure.
  486. */
  487. int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
  488. {
  489. u8 mtrr, uniform;
  490. mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform);
  491. if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
  492. (mtrr != MTRR_TYPE_WRBACK))
  493. return 0;
  494. prot = pgprot_4k_2_large(prot);
  495. set_pte((pte_t *)pud, pfn_pte(
  496. (u64)addr >> PAGE_SHIFT,
  497. __pgprot(pgprot_val(prot) | _PAGE_PSE)));
  498. return 1;
  499. }
  500. /**
  501. * pmd_set_huge - setup kernel PMD mapping
  502. *
  503. * See text over pud_set_huge() above.
  504. *
  505. * Returns 1 on success and 0 on failure.
  506. */
  507. int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
  508. {
  509. u8 mtrr, uniform;
  510. mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform);
  511. if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
  512. (mtrr != MTRR_TYPE_WRBACK)) {
  513. pr_warn_once("%s: Cannot satisfy [mem %#010llx-%#010llx] with a huge-page mapping due to MTRR override.\n",
  514. __func__, addr, addr + PMD_SIZE);
  515. return 0;
  516. }
  517. prot = pgprot_4k_2_large(prot);
  518. set_pte((pte_t *)pmd, pfn_pte(
  519. (u64)addr >> PAGE_SHIFT,
  520. __pgprot(pgprot_val(prot) | _PAGE_PSE)));
  521. return 1;
  522. }
  523. /**
  524. * pud_clear_huge - clear kernel PUD mapping when it is set
  525. *
  526. * Returns 1 on success and 0 on failure (no PUD map is found).
  527. */
  528. int pud_clear_huge(pud_t *pud)
  529. {
  530. if (pud_large(*pud)) {
  531. pud_clear(pud);
  532. return 1;
  533. }
  534. return 0;
  535. }
  536. /**
  537. * pmd_clear_huge - clear kernel PMD mapping when it is set
  538. *
  539. * Returns 1 on success and 0 on failure (no PMD map is found).
  540. */
  541. int pmd_clear_huge(pmd_t *pmd)
  542. {
  543. if (pmd_large(*pmd)) {
  544. pmd_clear(pmd);
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */