pgtable.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #ifndef _ASM_GENERIC_PGTABLE_H
  2. #define _ASM_GENERIC_PGTABLE_H
  3. #ifndef __ASSEMBLY__
  4. #ifdef CONFIG_MMU
  5. #include <linux/mm_types.h>
  6. #include <linux/bug.h>
  7. #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  8. extern int ptep_set_access_flags(struct vm_area_struct *vma,
  9. unsigned long address, pte_t *ptep,
  10. pte_t entry, int dirty);
  11. #endif
  12. #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
  13. extern int pmdp_set_access_flags(struct vm_area_struct *vma,
  14. unsigned long address, pmd_t *pmdp,
  15. pmd_t entry, int dirty);
  16. #endif
  17. #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  18. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  19. unsigned long address,
  20. pte_t *ptep)
  21. {
  22. pte_t pte = *ptep;
  23. int r = 1;
  24. if (!pte_young(pte))
  25. r = 0;
  26. else
  27. set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte));
  28. return r;
  29. }
  30. #endif
  31. #ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
  32. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  33. static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
  34. unsigned long address,
  35. pmd_t *pmdp)
  36. {
  37. pmd_t pmd = *pmdp;
  38. int r = 1;
  39. if (!pmd_young(pmd))
  40. r = 0;
  41. else
  42. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd));
  43. return r;
  44. }
  45. #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  46. static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
  47. unsigned long address,
  48. pmd_t *pmdp)
  49. {
  50. BUG();
  51. return 0;
  52. }
  53. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  54. #endif
  55. #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  56. int ptep_clear_flush_young(struct vm_area_struct *vma,
  57. unsigned long address, pte_t *ptep);
  58. #endif
  59. #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
  60. int pmdp_clear_flush_young(struct vm_area_struct *vma,
  61. unsigned long address, pmd_t *pmdp);
  62. #endif
  63. #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
  64. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  65. unsigned long address,
  66. pte_t *ptep)
  67. {
  68. pte_t pte = *ptep;
  69. pte_clear(mm, address, ptep);
  70. return pte;
  71. }
  72. #endif
  73. #ifndef __HAVE_ARCH_PMDP_GET_AND_CLEAR
  74. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  75. static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm,
  76. unsigned long address,
  77. pmd_t *pmdp)
  78. {
  79. pmd_t pmd = *pmdp;
  80. pmd_clear(pmdp);
  81. return pmd;
  82. }
  83. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  84. #endif
  85. #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  86. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  87. unsigned long address, pte_t *ptep,
  88. int full)
  89. {
  90. pte_t pte;
  91. pte = ptep_get_and_clear(mm, address, ptep);
  92. return pte;
  93. }
  94. #endif
  95. /*
  96. * Some architectures may be able to avoid expensive synchronization
  97. * primitives when modifications are made to PTE's which are already
  98. * not present, or in the process of an address space destruction.
  99. */
  100. #ifndef __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
  101. static inline void pte_clear_not_present_full(struct mm_struct *mm,
  102. unsigned long address,
  103. pte_t *ptep,
  104. int full)
  105. {
  106. pte_clear(mm, address, ptep);
  107. }
  108. #endif
  109. #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
  110. extern pte_t ptep_clear_flush(struct vm_area_struct *vma,
  111. unsigned long address,
  112. pte_t *ptep);
  113. #endif
  114. #ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH
  115. extern pmd_t pmdp_clear_flush(struct vm_area_struct *vma,
  116. unsigned long address,
  117. pmd_t *pmdp);
  118. #endif
  119. #ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT
  120. struct mm_struct;
  121. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long address, pte_t *ptep)
  122. {
  123. pte_t old_pte = *ptep;
  124. set_pte_at(mm, address, ptep, pte_wrprotect(old_pte));
  125. }
  126. #endif
  127. #ifndef __HAVE_ARCH_PMDP_SET_WRPROTECT
  128. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  129. static inline void pmdp_set_wrprotect(struct mm_struct *mm,
  130. unsigned long address, pmd_t *pmdp)
  131. {
  132. pmd_t old_pmd = *pmdp;
  133. set_pmd_at(mm, address, pmdp, pmd_wrprotect(old_pmd));
  134. }
  135. #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  136. static inline void pmdp_set_wrprotect(struct mm_struct *mm,
  137. unsigned long address, pmd_t *pmdp)
  138. {
  139. BUG();
  140. }
  141. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  142. #endif
  143. #ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  144. extern void pmdp_splitting_flush(struct vm_area_struct *vma,
  145. unsigned long address, pmd_t *pmdp);
  146. #endif
  147. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  148. extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable);
  149. #endif
  150. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  151. extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm);
  152. #endif
  153. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  154. extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  155. pmd_t *pmdp);
  156. #endif
  157. #ifndef __HAVE_ARCH_PTE_SAME
  158. static inline int pte_same(pte_t pte_a, pte_t pte_b)
  159. {
  160. return pte_val(pte_a) == pte_val(pte_b);
  161. }
  162. #endif
  163. #ifndef __HAVE_ARCH_PMD_SAME
  164. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  165. static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
  166. {
  167. return pmd_val(pmd_a) == pmd_val(pmd_b);
  168. }
  169. #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  170. static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
  171. {
  172. BUG();
  173. return 0;
  174. }
  175. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  176. #endif
  177. #ifndef __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
  178. #define page_test_and_clear_young(pfn) (0)
  179. #endif
  180. #ifndef __HAVE_ARCH_PGD_OFFSET_GATE
  181. #define pgd_offset_gate(mm, addr) pgd_offset(mm, addr)
  182. #endif
  183. #ifndef __HAVE_ARCH_MOVE_PTE
  184. #define move_pte(pte, prot, old_addr, new_addr) (pte)
  185. #endif
  186. #ifndef pte_accessible
  187. # define pte_accessible(pte) ((void)(pte),1)
  188. #endif
  189. #ifndef flush_tlb_fix_spurious_fault
  190. #define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address)
  191. #endif
  192. #ifndef pgprot_noncached
  193. #define pgprot_noncached(prot) (prot)
  194. #endif
  195. #ifndef pgprot_writecombine
  196. #define pgprot_writecombine pgprot_noncached
  197. #endif
  198. /*
  199. * When walking page tables, get the address of the next boundary,
  200. * or the end address of the range if that comes earlier. Although no
  201. * vma end wraps to 0, rounded up __boundary may wrap to 0 throughout.
  202. */
  203. #define pgd_addr_end(addr, end) \
  204. ({ unsigned long __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \
  205. (__boundary - 1 < (end) - 1)? __boundary: (end); \
  206. })
  207. #ifndef pud_addr_end
  208. #define pud_addr_end(addr, end) \
  209. ({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \
  210. (__boundary - 1 < (end) - 1)? __boundary: (end); \
  211. })
  212. #endif
  213. #ifndef pmd_addr_end
  214. #define pmd_addr_end(addr, end) \
  215. ({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \
  216. (__boundary - 1 < (end) - 1)? __boundary: (end); \
  217. })
  218. #endif
  219. /*
  220. * When walking page tables, we usually want to skip any p?d_none entries;
  221. * and any p?d_bad entries - reporting the error before resetting to none.
  222. * Do the tests inline, but report and clear the bad entry in mm/memory.c.
  223. */
  224. void pgd_clear_bad(pgd_t *);
  225. void pud_clear_bad(pud_t *);
  226. void pmd_clear_bad(pmd_t *);
  227. static inline int pgd_none_or_clear_bad(pgd_t *pgd)
  228. {
  229. if (pgd_none(*pgd))
  230. return 1;
  231. if (unlikely(pgd_bad(*pgd))) {
  232. pgd_clear_bad(pgd);
  233. return 1;
  234. }
  235. return 0;
  236. }
  237. static inline int pud_none_or_clear_bad(pud_t *pud)
  238. {
  239. if (pud_none(*pud))
  240. return 1;
  241. if (unlikely(pud_bad(*pud))) {
  242. pud_clear_bad(pud);
  243. return 1;
  244. }
  245. return 0;
  246. }
  247. static inline int pmd_none_or_clear_bad(pmd_t *pmd)
  248. {
  249. if (pmd_none(*pmd))
  250. return 1;
  251. if (unlikely(pmd_bad(*pmd))) {
  252. pmd_clear_bad(pmd);
  253. return 1;
  254. }
  255. return 0;
  256. }
  257. static inline pte_t __ptep_modify_prot_start(struct mm_struct *mm,
  258. unsigned long addr,
  259. pte_t *ptep)
  260. {
  261. /*
  262. * Get the current pte state, but zero it out to make it
  263. * non-present, preventing the hardware from asynchronously
  264. * updating it.
  265. */
  266. return ptep_get_and_clear(mm, addr, ptep);
  267. }
  268. static inline void __ptep_modify_prot_commit(struct mm_struct *mm,
  269. unsigned long addr,
  270. pte_t *ptep, pte_t pte)
  271. {
  272. /*
  273. * The pte is non-present, so there's no hardware state to
  274. * preserve.
  275. */
  276. set_pte_at(mm, addr, ptep, pte);
  277. }
  278. #ifndef __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
  279. /*
  280. * Start a pte protection read-modify-write transaction, which
  281. * protects against asynchronous hardware modifications to the pte.
  282. * The intention is not to prevent the hardware from making pte
  283. * updates, but to prevent any updates it may make from being lost.
  284. *
  285. * This does not protect against other software modifications of the
  286. * pte; the appropriate pte lock must be held over the transation.
  287. *
  288. * Note that this interface is intended to be batchable, meaning that
  289. * ptep_modify_prot_commit may not actually update the pte, but merely
  290. * queue the update to be done at some later time. The update must be
  291. * actually committed before the pte lock is released, however.
  292. */
  293. static inline pte_t ptep_modify_prot_start(struct mm_struct *mm,
  294. unsigned long addr,
  295. pte_t *ptep)
  296. {
  297. return __ptep_modify_prot_start(mm, addr, ptep);
  298. }
  299. /*
  300. * Commit an update to a pte, leaving any hardware-controlled bits in
  301. * the PTE unmodified.
  302. */
  303. static inline void ptep_modify_prot_commit(struct mm_struct *mm,
  304. unsigned long addr,
  305. pte_t *ptep, pte_t pte)
  306. {
  307. __ptep_modify_prot_commit(mm, addr, ptep, pte);
  308. }
  309. #endif /* __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION */
  310. #endif /* CONFIG_MMU */
  311. /*
  312. * A facility to provide lazy MMU batching. This allows PTE updates and
  313. * page invalidations to be delayed until a call to leave lazy MMU mode
  314. * is issued. Some architectures may benefit from doing this, and it is
  315. * beneficial for both shadow and direct mode hypervisors, which may batch
  316. * the PTE updates which happen during this window. Note that using this
  317. * interface requires that read hazards be removed from the code. A read
  318. * hazard could result in the direct mode hypervisor case, since the actual
  319. * write to the page tables may not yet have taken place, so reads though
  320. * a raw PTE pointer after it has been modified are not guaranteed to be
  321. * up to date. This mode can only be entered and left under the protection of
  322. * the page table locks for all page tables which may be modified. In the UP
  323. * case, this is required so that preemption is disabled, and in the SMP case,
  324. * it must synchronize the delayed page table writes properly on other CPUs.
  325. */
  326. #ifndef __HAVE_ARCH_ENTER_LAZY_MMU_MODE
  327. #define arch_enter_lazy_mmu_mode() do {} while (0)
  328. #define arch_leave_lazy_mmu_mode() do {} while (0)
  329. #define arch_flush_lazy_mmu_mode() do {} while (0)
  330. #endif
  331. /*
  332. * A facility to provide batching of the reload of page tables and
  333. * other process state with the actual context switch code for
  334. * paravirtualized guests. By convention, only one of the batched
  335. * update (lazy) modes (CPU, MMU) should be active at any given time,
  336. * entry should never be nested, and entry and exits should always be
  337. * paired. This is for sanity of maintaining and reasoning about the
  338. * kernel code. In this case, the exit (end of the context switch) is
  339. * in architecture-specific code, and so doesn't need a generic
  340. * definition.
  341. */
  342. #ifndef __HAVE_ARCH_START_CONTEXT_SWITCH
  343. #define arch_start_context_switch(prev) do {} while (0)
  344. #endif
  345. #ifndef __HAVE_PFNMAP_TRACKING
  346. /*
  347. * Interfaces that can be used by architecture code to keep track of
  348. * memory type of pfn mappings specified by the remap_pfn_range,
  349. * vm_insert_pfn.
  350. */
  351. /*
  352. * track_pfn_remap is called when a _new_ pfn mapping is being established
  353. * by remap_pfn_range() for physical range indicated by pfn and size.
  354. */
  355. static inline int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
  356. unsigned long pfn, unsigned long addr,
  357. unsigned long size)
  358. {
  359. return 0;
  360. }
  361. /*
  362. * track_pfn_insert is called when a _new_ single pfn is established
  363. * by vm_insert_pfn().
  364. */
  365. static inline int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
  366. unsigned long pfn)
  367. {
  368. return 0;
  369. }
  370. /*
  371. * track_pfn_copy is called when vma that is covering the pfnmap gets
  372. * copied through copy_page_range().
  373. */
  374. static inline int track_pfn_copy(struct vm_area_struct *vma)
  375. {
  376. return 0;
  377. }
  378. /*
  379. * untrack_pfn_vma is called while unmapping a pfnmap for a region.
  380. * untrack can be called for a specific region indicated by pfn and size or
  381. * can be for the entire vma (in which case pfn, size are zero).
  382. */
  383. static inline void untrack_pfn(struct vm_area_struct *vma,
  384. unsigned long pfn, unsigned long size)
  385. {
  386. }
  387. #else
  388. extern int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
  389. unsigned long pfn, unsigned long addr,
  390. unsigned long size);
  391. extern int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
  392. unsigned long pfn);
  393. extern int track_pfn_copy(struct vm_area_struct *vma);
  394. extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
  395. unsigned long size);
  396. #endif
  397. #ifdef __HAVE_COLOR_ZERO_PAGE
  398. static inline int is_zero_pfn(unsigned long pfn)
  399. {
  400. extern unsigned long zero_pfn;
  401. unsigned long offset_from_zero_pfn = pfn - zero_pfn;
  402. return offset_from_zero_pfn <= (zero_page_mask >> PAGE_SHIFT);
  403. }
  404. #define my_zero_pfn(addr) page_to_pfn(ZERO_PAGE(addr))
  405. #else
  406. static inline int is_zero_pfn(unsigned long pfn)
  407. {
  408. extern unsigned long zero_pfn;
  409. return pfn == zero_pfn;
  410. }
  411. static inline unsigned long my_zero_pfn(unsigned long addr)
  412. {
  413. extern unsigned long zero_pfn;
  414. return zero_pfn;
  415. }
  416. #endif
  417. #ifdef CONFIG_MMU
  418. #ifndef CONFIG_TRANSPARENT_HUGEPAGE
  419. static inline int pmd_trans_huge(pmd_t pmd)
  420. {
  421. return 0;
  422. }
  423. static inline int pmd_trans_splitting(pmd_t pmd)
  424. {
  425. return 0;
  426. }
  427. #ifndef __HAVE_ARCH_PMD_WRITE
  428. static inline int pmd_write(pmd_t pmd)
  429. {
  430. BUG();
  431. return 0;
  432. }
  433. #endif /* __HAVE_ARCH_PMD_WRITE */
  434. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  435. #ifndef pmd_read_atomic
  436. static inline pmd_t pmd_read_atomic(pmd_t *pmdp)
  437. {
  438. /*
  439. * Depend on compiler for an atomic pmd read. NOTE: this is
  440. * only going to work, if the pmdval_t isn't larger than
  441. * an unsigned long.
  442. */
  443. return *pmdp;
  444. }
  445. #endif
  446. /*
  447. * This function is meant to be used by sites walking pagetables with
  448. * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
  449. * transhuge page faults. MADV_DONTNEED can convert a transhuge pmd
  450. * into a null pmd and the transhuge page fault can convert a null pmd
  451. * into an hugepmd or into a regular pmd (if the hugepage allocation
  452. * fails). While holding the mmap_sem in read mode the pmd becomes
  453. * stable and stops changing under us only if it's not null and not a
  454. * transhuge pmd. When those races occurs and this function makes a
  455. * difference vs the standard pmd_none_or_clear_bad, the result is
  456. * undefined so behaving like if the pmd was none is safe (because it
  457. * can return none anyway). The compiler level barrier() is critically
  458. * important to compute the two checks atomically on the same pmdval.
  459. *
  460. * For 32bit kernels with a 64bit large pmd_t this automatically takes
  461. * care of reading the pmd atomically to avoid SMP race conditions
  462. * against pmd_populate() when the mmap_sem is hold for reading by the
  463. * caller (a special atomic read not done by "gcc" as in the generic
  464. * version above, is also needed when THP is disabled because the page
  465. * fault can populate the pmd from under us).
  466. */
  467. static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
  468. {
  469. pmd_t pmdval = pmd_read_atomic(pmd);
  470. /*
  471. * The barrier will stabilize the pmdval in a register or on
  472. * the stack so that it will stop changing under the code.
  473. *
  474. * When CONFIG_TRANSPARENT_HUGEPAGE=y on x86 32bit PAE,
  475. * pmd_read_atomic is allowed to return a not atomic pmdval
  476. * (for example pointing to an hugepage that has never been
  477. * mapped in the pmd). The below checks will only care about
  478. * the low part of the pmd with 32bit PAE x86 anyway, with the
  479. * exception of pmd_none(). So the important thing is that if
  480. * the low part of the pmd is found null, the high part will
  481. * be also null or the pmd_none() check below would be
  482. * confused.
  483. */
  484. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  485. barrier();
  486. #endif
  487. if (pmd_none(pmdval))
  488. return 1;
  489. if (unlikely(pmd_bad(pmdval))) {
  490. if (!pmd_trans_huge(pmdval))
  491. pmd_clear_bad(pmd);
  492. return 1;
  493. }
  494. return 0;
  495. }
  496. /*
  497. * This is a noop if Transparent Hugepage Support is not built into
  498. * the kernel. Otherwise it is equivalent to
  499. * pmd_none_or_trans_huge_or_clear_bad(), and shall only be called in
  500. * places that already verified the pmd is not none and they want to
  501. * walk ptes while holding the mmap sem in read mode (write mode don't
  502. * need this). If THP is not enabled, the pmd can't go away under the
  503. * code even if MADV_DONTNEED runs, but if THP is enabled we need to
  504. * run a pmd_trans_unstable before walking the ptes after
  505. * split_huge_page_pmd returns (because it may have run when the pmd
  506. * become null, but then a page fault can map in a THP and not a
  507. * regular page).
  508. */
  509. static inline int pmd_trans_unstable(pmd_t *pmd)
  510. {
  511. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  512. return pmd_none_or_trans_huge_or_clear_bad(pmd);
  513. #else
  514. return 0;
  515. #endif
  516. }
  517. #ifdef CONFIG_NUMA_BALANCING
  518. #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
  519. /*
  520. * _PAGE_NUMA works identical to _PAGE_PROTNONE (it's actually the
  521. * same bit too). It's set only when _PAGE_PRESET is not set and it's
  522. * never set if _PAGE_PRESENT is set.
  523. *
  524. * pte/pmd_present() returns true if pte/pmd_numa returns true. Page
  525. * fault triggers on those regions if pte/pmd_numa returns true
  526. * (because _PAGE_PRESENT is not set).
  527. */
  528. #ifndef pte_numa
  529. static inline int pte_numa(pte_t pte)
  530. {
  531. return (pte_flags(pte) &
  532. (_PAGE_NUMA|_PAGE_PRESENT)) == _PAGE_NUMA;
  533. }
  534. #endif
  535. #ifndef pmd_numa
  536. static inline int pmd_numa(pmd_t pmd)
  537. {
  538. return (pmd_flags(pmd) &
  539. (_PAGE_NUMA|_PAGE_PRESENT)) == _PAGE_NUMA;
  540. }
  541. #endif
  542. /*
  543. * pte/pmd_mknuma sets the _PAGE_ACCESSED bitflag automatically
  544. * because they're called by the NUMA hinting minor page fault. If we
  545. * wouldn't set the _PAGE_ACCESSED bitflag here, the TLB miss handler
  546. * would be forced to set it later while filling the TLB after we
  547. * return to userland. That would trigger a second write to memory
  548. * that we optimize away by setting _PAGE_ACCESSED here.
  549. */
  550. #ifndef pte_mknonnuma
  551. static inline pte_t pte_mknonnuma(pte_t pte)
  552. {
  553. pte = pte_clear_flags(pte, _PAGE_NUMA);
  554. return pte_set_flags(pte, _PAGE_PRESENT|_PAGE_ACCESSED);
  555. }
  556. #endif
  557. #ifndef pmd_mknonnuma
  558. static inline pmd_t pmd_mknonnuma(pmd_t pmd)
  559. {
  560. pmd = pmd_clear_flags(pmd, _PAGE_NUMA);
  561. return pmd_set_flags(pmd, _PAGE_PRESENT|_PAGE_ACCESSED);
  562. }
  563. #endif
  564. #ifndef pte_mknuma
  565. static inline pte_t pte_mknuma(pte_t pte)
  566. {
  567. pte = pte_set_flags(pte, _PAGE_NUMA);
  568. return pte_clear_flags(pte, _PAGE_PRESENT);
  569. }
  570. #endif
  571. #ifndef pmd_mknuma
  572. static inline pmd_t pmd_mknuma(pmd_t pmd)
  573. {
  574. pmd = pmd_set_flags(pmd, _PAGE_NUMA);
  575. return pmd_clear_flags(pmd, _PAGE_PRESENT);
  576. }
  577. #endif
  578. #else
  579. extern int pte_numa(pte_t pte);
  580. extern int pmd_numa(pmd_t pmd);
  581. extern pte_t pte_mknonnuma(pte_t pte);
  582. extern pmd_t pmd_mknonnuma(pmd_t pmd);
  583. extern pte_t pte_mknuma(pte_t pte);
  584. extern pmd_t pmd_mknuma(pmd_t pmd);
  585. #endif /* CONFIG_ARCH_USES_NUMA_PROT_NONE */
  586. #else
  587. static inline int pmd_numa(pmd_t pmd)
  588. {
  589. return 0;
  590. }
  591. static inline int pte_numa(pte_t pte)
  592. {
  593. return 0;
  594. }
  595. static inline pte_t pte_mknonnuma(pte_t pte)
  596. {
  597. return pte;
  598. }
  599. static inline pmd_t pmd_mknonnuma(pmd_t pmd)
  600. {
  601. return pmd;
  602. }
  603. static inline pte_t pte_mknuma(pte_t pte)
  604. {
  605. return pte;
  606. }
  607. static inline pmd_t pmd_mknuma(pmd_t pmd)
  608. {
  609. return pmd;
  610. }
  611. #endif /* CONFIG_NUMA_BALANCING */
  612. #endif /* CONFIG_MMU */
  613. #endif /* !__ASSEMBLY__ */
  614. #endif /* _ASM_GENERIC_PGTABLE_H */