pgtable.h 16 KB

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