pgtable.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #ifndef _ASM_X86_PGTABLE_H
  2. #define _ASM_X86_PGTABLE_H
  3. #define FIRST_USER_ADDRESS 0
  4. #define _PAGE_BIT_PRESENT 0 /* is present */
  5. #define _PAGE_BIT_RW 1 /* writeable */
  6. #define _PAGE_BIT_USER 2 /* userspace addressable */
  7. #define _PAGE_BIT_PWT 3 /* page write through */
  8. #define _PAGE_BIT_PCD 4 /* page cache disabled */
  9. #define _PAGE_BIT_ACCESSED 5 /* was accessed (raised by CPU) */
  10. #define _PAGE_BIT_DIRTY 6 /* was written to (raised by CPU) */
  11. #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
  12. #define _PAGE_BIT_PAT 7 /* on 4KB pages */
  13. #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
  14. #define _PAGE_BIT_UNUSED1 9 /* available for programmer */
  15. #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
  16. #define _PAGE_BIT_UNUSED3 11
  17. #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
  18. #define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
  19. #define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
  20. #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
  21. /* If _PAGE_BIT_PRESENT is clear, we use these: */
  22. /* - if the user mapped it with PROT_NONE; pte_present gives true */
  23. #define _PAGE_BIT_PROTNONE _PAGE_BIT_GLOBAL
  24. /* - set: nonlinear file mapping, saved PTE; unset:swap */
  25. #define _PAGE_BIT_FILE _PAGE_BIT_DIRTY
  26. #define _PAGE_PRESENT (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
  27. #define _PAGE_RW (_AT(pteval_t, 1) << _PAGE_BIT_RW)
  28. #define _PAGE_USER (_AT(pteval_t, 1) << _PAGE_BIT_USER)
  29. #define _PAGE_PWT (_AT(pteval_t, 1) << _PAGE_BIT_PWT)
  30. #define _PAGE_PCD (_AT(pteval_t, 1) << _PAGE_BIT_PCD)
  31. #define _PAGE_ACCESSED (_AT(pteval_t, 1) << _PAGE_BIT_ACCESSED)
  32. #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
  33. #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
  34. #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
  35. #define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
  36. #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
  37. #define _PAGE_UNUSED3 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
  38. #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
  39. #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
  40. #define _PAGE_SPECIAL (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
  41. #define _PAGE_CPA_TEST (_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
  42. #define __HAVE_ARCH_PTE_SPECIAL
  43. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  44. #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
  45. #else
  46. #define _PAGE_NX (_AT(pteval_t, 0))
  47. #endif
  48. #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
  49. #define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)
  50. #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
  51. _PAGE_ACCESSED | _PAGE_DIRTY)
  52. #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | \
  53. _PAGE_DIRTY)
  54. /* Set of bits not changed in pte_modify */
  55. #define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \
  56. _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY)
  57. #define _PAGE_CACHE_MASK (_PAGE_PCD | _PAGE_PWT)
  58. #define _PAGE_CACHE_WB (0)
  59. #define _PAGE_CACHE_WC (_PAGE_PWT)
  60. #define _PAGE_CACHE_UC_MINUS (_PAGE_PCD)
  61. #define _PAGE_CACHE_UC (_PAGE_PCD | _PAGE_PWT)
  62. #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
  63. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
  64. _PAGE_ACCESSED | _PAGE_NX)
  65. #define PAGE_SHARED_EXEC __pgprot(_PAGE_PRESENT | _PAGE_RW | \
  66. _PAGE_USER | _PAGE_ACCESSED)
  67. #define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
  68. _PAGE_ACCESSED | _PAGE_NX)
  69. #define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
  70. _PAGE_ACCESSED)
  71. #define PAGE_COPY PAGE_COPY_NOEXEC
  72. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | \
  73. _PAGE_ACCESSED | _PAGE_NX)
  74. #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
  75. _PAGE_ACCESSED)
  76. #define __PAGE_KERNEL_EXEC \
  77. (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
  78. #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
  79. #define __PAGE_KERNEL_RO (__PAGE_KERNEL & ~_PAGE_RW)
  80. #define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
  81. #define __PAGE_KERNEL_EXEC_NOCACHE (__PAGE_KERNEL_EXEC | _PAGE_PCD | _PAGE_PWT)
  82. #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
  83. #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
  84. #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
  85. #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
  86. #define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
  87. #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
  88. #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
  89. #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
  90. #define __PAGE_KERNEL_IO (__PAGE_KERNEL | _PAGE_IOMAP)
  91. #define __PAGE_KERNEL_IO_NOCACHE (__PAGE_KERNEL_NOCACHE | _PAGE_IOMAP)
  92. #define __PAGE_KERNEL_IO_UC_MINUS (__PAGE_KERNEL_UC_MINUS | _PAGE_IOMAP)
  93. #define __PAGE_KERNEL_IO_WC (__PAGE_KERNEL_WC | _PAGE_IOMAP)
  94. #define PAGE_KERNEL __pgprot(__PAGE_KERNEL)
  95. #define PAGE_KERNEL_RO __pgprot(__PAGE_KERNEL_RO)
  96. #define PAGE_KERNEL_EXEC __pgprot(__PAGE_KERNEL_EXEC)
  97. #define PAGE_KERNEL_RX __pgprot(__PAGE_KERNEL_RX)
  98. #define PAGE_KERNEL_WC __pgprot(__PAGE_KERNEL_WC)
  99. #define PAGE_KERNEL_NOCACHE __pgprot(__PAGE_KERNEL_NOCACHE)
  100. #define PAGE_KERNEL_UC_MINUS __pgprot(__PAGE_KERNEL_UC_MINUS)
  101. #define PAGE_KERNEL_EXEC_NOCACHE __pgprot(__PAGE_KERNEL_EXEC_NOCACHE)
  102. #define PAGE_KERNEL_LARGE __pgprot(__PAGE_KERNEL_LARGE)
  103. #define PAGE_KERNEL_LARGE_NOCACHE __pgprot(__PAGE_KERNEL_LARGE_NOCACHE)
  104. #define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC)
  105. #define PAGE_KERNEL_VSYSCALL __pgprot(__PAGE_KERNEL_VSYSCALL)
  106. #define PAGE_KERNEL_VSYSCALL_NOCACHE __pgprot(__PAGE_KERNEL_VSYSCALL_NOCACHE)
  107. #define PAGE_KERNEL_IO __pgprot(__PAGE_KERNEL_IO)
  108. #define PAGE_KERNEL_IO_NOCACHE __pgprot(__PAGE_KERNEL_IO_NOCACHE)
  109. #define PAGE_KERNEL_IO_UC_MINUS __pgprot(__PAGE_KERNEL_IO_UC_MINUS)
  110. #define PAGE_KERNEL_IO_WC __pgprot(__PAGE_KERNEL_IO_WC)
  111. /* xwr */
  112. #define __P000 PAGE_NONE
  113. #define __P001 PAGE_READONLY
  114. #define __P010 PAGE_COPY
  115. #define __P011 PAGE_COPY
  116. #define __P100 PAGE_READONLY_EXEC
  117. #define __P101 PAGE_READONLY_EXEC
  118. #define __P110 PAGE_COPY_EXEC
  119. #define __P111 PAGE_COPY_EXEC
  120. #define __S000 PAGE_NONE
  121. #define __S001 PAGE_READONLY
  122. #define __S010 PAGE_SHARED
  123. #define __S011 PAGE_SHARED
  124. #define __S100 PAGE_READONLY_EXEC
  125. #define __S101 PAGE_READONLY_EXEC
  126. #define __S110 PAGE_SHARED_EXEC
  127. #define __S111 PAGE_SHARED_EXEC
  128. /*
  129. * early identity mapping pte attrib macros.
  130. */
  131. #ifdef CONFIG_X86_64
  132. #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
  133. #else
  134. /*
  135. * For PDE_IDENT_ATTR include USER bit. As the PDE and PTE protection
  136. * bits are combined, this will alow user to access the high address mapped
  137. * VDSO in the presence of CONFIG_COMPAT_VDSO
  138. */
  139. #define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
  140. #define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
  141. #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
  142. #endif
  143. /*
  144. * Macro to mark a page protection value as UC-
  145. */
  146. #define pgprot_noncached(prot) \
  147. ((boot_cpu_data.x86 > 3) \
  148. ? (__pgprot(pgprot_val(prot) | _PAGE_CACHE_UC_MINUS)) \
  149. : (prot))
  150. #ifndef __ASSEMBLY__
  151. #define pgprot_writecombine pgprot_writecombine
  152. extern pgprot_t pgprot_writecombine(pgprot_t prot);
  153. /*
  154. * ZERO_PAGE is a global shared page that is always zero: used
  155. * for zero-mapped memory areas etc..
  156. */
  157. extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
  158. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  159. extern spinlock_t pgd_lock;
  160. extern struct list_head pgd_list;
  161. /*
  162. * The following only work if pte_present() is true.
  163. * Undefined behaviour if not..
  164. */
  165. static inline int pte_dirty(pte_t pte)
  166. {
  167. return pte_flags(pte) & _PAGE_DIRTY;
  168. }
  169. static inline int pte_young(pte_t pte)
  170. {
  171. return pte_flags(pte) & _PAGE_ACCESSED;
  172. }
  173. static inline int pte_write(pte_t pte)
  174. {
  175. return pte_flags(pte) & _PAGE_RW;
  176. }
  177. static inline int pte_file(pte_t pte)
  178. {
  179. return pte_flags(pte) & _PAGE_FILE;
  180. }
  181. static inline int pte_huge(pte_t pte)
  182. {
  183. return pte_flags(pte) & _PAGE_PSE;
  184. }
  185. static inline int pte_global(pte_t pte)
  186. {
  187. return pte_flags(pte) & _PAGE_GLOBAL;
  188. }
  189. static inline int pte_exec(pte_t pte)
  190. {
  191. return !(pte_flags(pte) & _PAGE_NX);
  192. }
  193. static inline int pte_special(pte_t pte)
  194. {
  195. return pte_flags(pte) & _PAGE_SPECIAL;
  196. }
  197. static inline unsigned long pte_pfn(pte_t pte)
  198. {
  199. return (pte_val(pte) & PTE_PFN_MASK) >> PAGE_SHIFT;
  200. }
  201. #define pte_page(pte) pfn_to_page(pte_pfn(pte))
  202. static inline int pmd_large(pmd_t pte)
  203. {
  204. return (pmd_val(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
  205. (_PAGE_PSE | _PAGE_PRESENT);
  206. }
  207. static inline pte_t pte_mkclean(pte_t pte)
  208. {
  209. return __pte(pte_val(pte) & ~_PAGE_DIRTY);
  210. }
  211. static inline pte_t pte_mkold(pte_t pte)
  212. {
  213. return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
  214. }
  215. static inline pte_t pte_wrprotect(pte_t pte)
  216. {
  217. return __pte(pte_val(pte) & ~_PAGE_RW);
  218. }
  219. static inline pte_t pte_mkexec(pte_t pte)
  220. {
  221. return __pte(pte_val(pte) & ~_PAGE_NX);
  222. }
  223. static inline pte_t pte_mkdirty(pte_t pte)
  224. {
  225. return __pte(pte_val(pte) | _PAGE_DIRTY);
  226. }
  227. static inline pte_t pte_mkyoung(pte_t pte)
  228. {
  229. return __pte(pte_val(pte) | _PAGE_ACCESSED);
  230. }
  231. static inline pte_t pte_mkwrite(pte_t pte)
  232. {
  233. return __pte(pte_val(pte) | _PAGE_RW);
  234. }
  235. static inline pte_t pte_mkhuge(pte_t pte)
  236. {
  237. return __pte(pte_val(pte) | _PAGE_PSE);
  238. }
  239. static inline pte_t pte_clrhuge(pte_t pte)
  240. {
  241. return __pte(pte_val(pte) & ~_PAGE_PSE);
  242. }
  243. static inline pte_t pte_mkglobal(pte_t pte)
  244. {
  245. return __pte(pte_val(pte) | _PAGE_GLOBAL);
  246. }
  247. static inline pte_t pte_clrglobal(pte_t pte)
  248. {
  249. return __pte(pte_val(pte) & ~_PAGE_GLOBAL);
  250. }
  251. static inline pte_t pte_mkspecial(pte_t pte)
  252. {
  253. return __pte(pte_val(pte) | _PAGE_SPECIAL);
  254. }
  255. extern pteval_t __supported_pte_mask;
  256. static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
  257. {
  258. return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
  259. pgprot_val(pgprot)) & __supported_pte_mask);
  260. }
  261. static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
  262. {
  263. return __pmd((((phys_addr_t)page_nr << PAGE_SHIFT) |
  264. pgprot_val(pgprot)) & __supported_pte_mask);
  265. }
  266. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  267. {
  268. pteval_t val = pte_val(pte);
  269. /*
  270. * Chop off the NX bit (if present), and add the NX portion of
  271. * the newprot (if present):
  272. */
  273. val &= _PAGE_CHG_MASK;
  274. val |= pgprot_val(newprot) & (~_PAGE_CHG_MASK) & __supported_pte_mask;
  275. return __pte(val);
  276. }
  277. /* mprotect needs to preserve PAT bits when updating vm_page_prot */
  278. #define pgprot_modify pgprot_modify
  279. static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
  280. {
  281. pgprotval_t preservebits = pgprot_val(oldprot) & _PAGE_CHG_MASK;
  282. pgprotval_t addbits = pgprot_val(newprot);
  283. return __pgprot(preservebits | addbits);
  284. }
  285. #define pte_pgprot(x) __pgprot(pte_flags(x) & PTE_FLAGS_MASK)
  286. #define canon_pgprot(p) __pgprot(pgprot_val(p) & __supported_pte_mask)
  287. #ifndef __ASSEMBLY__
  288. /* Indicate that x86 has its own track and untrack pfn vma functions */
  289. #define __HAVE_PFNMAP_TRACKING
  290. #define __HAVE_PHYS_MEM_ACCESS_PROT
  291. struct file;
  292. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  293. unsigned long size, pgprot_t vma_prot);
  294. int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
  295. unsigned long size, pgprot_t *vma_prot);
  296. #endif
  297. /* Install a pte for a particular vaddr in kernel space. */
  298. void set_pte_vaddr(unsigned long vaddr, pte_t pte);
  299. #ifdef CONFIG_X86_32
  300. extern void native_pagetable_setup_start(pgd_t *base);
  301. extern void native_pagetable_setup_done(pgd_t *base);
  302. #else
  303. static inline void native_pagetable_setup_start(pgd_t *base) {}
  304. static inline void native_pagetable_setup_done(pgd_t *base) {}
  305. #endif
  306. struct seq_file;
  307. extern void arch_report_meminfo(struct seq_file *m);
  308. #ifdef CONFIG_PARAVIRT
  309. #include <asm/paravirt.h>
  310. #else /* !CONFIG_PARAVIRT */
  311. #define set_pte(ptep, pte) native_set_pte(ptep, pte)
  312. #define set_pte_at(mm, addr, ptep, pte) native_set_pte_at(mm, addr, ptep, pte)
  313. #define set_pte_present(mm, addr, ptep, pte) \
  314. native_set_pte_present(mm, addr, ptep, pte)
  315. #define set_pte_atomic(ptep, pte) \
  316. native_set_pte_atomic(ptep, pte)
  317. #define set_pmd(pmdp, pmd) native_set_pmd(pmdp, pmd)
  318. #ifndef __PAGETABLE_PUD_FOLDED
  319. #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
  320. #define pgd_clear(pgd) native_pgd_clear(pgd)
  321. #endif
  322. #ifndef set_pud
  323. # define set_pud(pudp, pud) native_set_pud(pudp, pud)
  324. #endif
  325. #ifndef __PAGETABLE_PMD_FOLDED
  326. #define pud_clear(pud) native_pud_clear(pud)
  327. #endif
  328. #define pte_clear(mm, addr, ptep) native_pte_clear(mm, addr, ptep)
  329. #define pmd_clear(pmd) native_pmd_clear(pmd)
  330. #define pte_update(mm, addr, ptep) do { } while (0)
  331. #define pte_update_defer(mm, addr, ptep) do { } while (0)
  332. static inline void __init paravirt_pagetable_setup_start(pgd_t *base)
  333. {
  334. native_pagetable_setup_start(base);
  335. }
  336. static inline void __init paravirt_pagetable_setup_done(pgd_t *base)
  337. {
  338. native_pagetable_setup_done(base);
  339. }
  340. #endif /* CONFIG_PARAVIRT */
  341. #endif /* __ASSEMBLY__ */
  342. #ifdef CONFIG_X86_32
  343. # include "pgtable_32.h"
  344. #else
  345. # include "pgtable_64.h"
  346. #endif
  347. /*
  348. * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
  349. *
  350. * this macro returns the index of the entry in the pgd page which would
  351. * control the given virtual address
  352. */
  353. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  354. /*
  355. * pgd_offset() returns a (pgd_t *)
  356. * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
  357. */
  358. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
  359. /*
  360. * a shortcut which implies the use of the kernel's pgd, instead
  361. * of a process's
  362. */
  363. #define pgd_offset_k(address) pgd_offset(&init_mm, (address))
  364. #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
  365. #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
  366. #ifndef __ASSEMBLY__
  367. enum {
  368. PG_LEVEL_NONE,
  369. PG_LEVEL_4K,
  370. PG_LEVEL_2M,
  371. PG_LEVEL_1G,
  372. PG_LEVEL_NUM
  373. };
  374. #ifdef CONFIG_PROC_FS
  375. extern void update_page_count(int level, unsigned long pages);
  376. #else
  377. static inline void update_page_count(int level, unsigned long pages) { }
  378. #endif
  379. /*
  380. * Helper function that returns the kernel pagetable entry controlling
  381. * the virtual address 'address'. NULL means no pagetable entry present.
  382. * NOTE: the return type is pte_t but if the pmd is PSE then we return it
  383. * as a pte too.
  384. */
  385. extern pte_t *lookup_address(unsigned long address, unsigned int *level);
  386. /* local pte updates need not use xchg for locking */
  387. static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
  388. {
  389. pte_t res = *ptep;
  390. /* Pure native function needs no input for mm, addr */
  391. native_pte_clear(NULL, 0, ptep);
  392. return res;
  393. }
  394. static inline void native_set_pte_at(struct mm_struct *mm, unsigned long addr,
  395. pte_t *ptep , pte_t pte)
  396. {
  397. native_set_pte(ptep, pte);
  398. }
  399. #ifndef CONFIG_PARAVIRT
  400. /*
  401. * Rules for using pte_update - it must be called after any PTE update which
  402. * has not been done using the set_pte / clear_pte interfaces. It is used by
  403. * shadow mode hypervisors to resynchronize the shadow page tables. Kernel PTE
  404. * updates should either be sets, clears, or set_pte_atomic for P->P
  405. * transitions, which means this hook should only be called for user PTEs.
  406. * This hook implies a P->P protection or access change has taken place, which
  407. * requires a subsequent TLB flush. The notification can optionally be delayed
  408. * until the TLB flush event by using the pte_update_defer form of the
  409. * interface, but care must be taken to assure that the flush happens while
  410. * still holding the same page table lock so that the shadow and primary pages
  411. * do not become out of sync on SMP.
  412. */
  413. #define pte_update(mm, addr, ptep) do { } while (0)
  414. #define pte_update_defer(mm, addr, ptep) do { } while (0)
  415. #endif
  416. /*
  417. * We only update the dirty/accessed state if we set
  418. * the dirty bit by hand in the kernel, since the hardware
  419. * will do the accessed bit for us, and we don't want to
  420. * race with other CPU's that might be updating the dirty
  421. * bit at the same time.
  422. */
  423. struct vm_area_struct;
  424. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  425. extern int ptep_set_access_flags(struct vm_area_struct *vma,
  426. unsigned long address, pte_t *ptep,
  427. pte_t entry, int dirty);
  428. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  429. extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
  430. unsigned long addr, pte_t *ptep);
  431. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  432. extern int ptep_clear_flush_young(struct vm_area_struct *vma,
  433. unsigned long address, pte_t *ptep);
  434. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  435. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  436. pte_t *ptep)
  437. {
  438. pte_t pte = native_ptep_get_and_clear(ptep);
  439. pte_update(mm, addr, ptep);
  440. return pte;
  441. }
  442. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  443. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  444. unsigned long addr, pte_t *ptep,
  445. int full)
  446. {
  447. pte_t pte;
  448. if (full) {
  449. /*
  450. * Full address destruction in progress; paravirt does not
  451. * care about updates and native needs no locking
  452. */
  453. pte = native_local_ptep_get_and_clear(ptep);
  454. } else {
  455. pte = ptep_get_and_clear(mm, addr, ptep);
  456. }
  457. return pte;
  458. }
  459. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  460. static inline void ptep_set_wrprotect(struct mm_struct *mm,
  461. unsigned long addr, pte_t *ptep)
  462. {
  463. clear_bit(_PAGE_BIT_RW, (unsigned long *)&ptep->pte);
  464. pte_update(mm, addr, ptep);
  465. }
  466. /*
  467. * clone_pgd_range(pgd_t *dst, pgd_t *src, int count);
  468. *
  469. * dst - pointer to pgd range anwhere on a pgd page
  470. * src - ""
  471. * count - the number of pgds to copy.
  472. *
  473. * dst and src can be on the same page, but the range must not overlap,
  474. * and must not cross a page boundary.
  475. */
  476. static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
  477. {
  478. memcpy(dst, src, count * sizeof(pgd_t));
  479. }
  480. #include <asm-generic/pgtable.h>
  481. #endif /* __ASSEMBLY__ */
  482. #endif /* _ASM_X86_PGTABLE_H */