pgtable.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. /*
  2. * include/asm-s390/pgtable.h
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Hartmut Penner (hp@de.ibm.com)
  7. * Ulrich Weigand (weigand@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. *
  10. * Derived from "include/asm-i386/pgtable.h"
  11. */
  12. #ifndef _ASM_S390_PGTABLE_H
  13. #define _ASM_S390_PGTABLE_H
  14. /*
  15. * The Linux memory management assumes a three-level page table setup. For
  16. * s390 31 bit we "fold" the mid level into the top-level page table, so
  17. * that we physically have the same two-level page table as the s390 mmu
  18. * expects in 31 bit mode. For s390 64 bit we use three of the five levels
  19. * the hardware provides (region first and region second tables are not
  20. * used).
  21. *
  22. * The "pgd_xxx()" functions are trivial for a folded two-level
  23. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  24. * into the pgd entry)
  25. *
  26. * This file contains the functions and defines necessary to modify and use
  27. * the S390 page table tree.
  28. */
  29. #ifndef __ASSEMBLY__
  30. #include <linux/sched.h>
  31. #include <linux/mm_types.h>
  32. #include <asm/bitops.h>
  33. #include <asm/bug.h>
  34. #include <asm/processor.h>
  35. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  36. extern void paging_init(void);
  37. extern void vmem_map_init(void);
  38. /*
  39. * The S390 doesn't have any external MMU info: the kernel page
  40. * tables contain all the necessary information.
  41. */
  42. #define update_mmu_cache(vma, address, pte) do { } while (0)
  43. /*
  44. * ZERO_PAGE is a global shared page that is always zero: used
  45. * for zero-mapped memory areas etc..
  46. */
  47. extern char empty_zero_page[PAGE_SIZE];
  48. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  49. #endif /* !__ASSEMBLY__ */
  50. /*
  51. * PMD_SHIFT determines the size of the area a second-level page
  52. * table can map
  53. * PGDIR_SHIFT determines what a third-level page table entry can map
  54. */
  55. #ifndef __s390x__
  56. # define PMD_SHIFT 20
  57. # define PUD_SHIFT 20
  58. # define PGDIR_SHIFT 20
  59. #else /* __s390x__ */
  60. # define PMD_SHIFT 20
  61. # define PUD_SHIFT 31
  62. # define PGDIR_SHIFT 42
  63. #endif /* __s390x__ */
  64. #define PMD_SIZE (1UL << PMD_SHIFT)
  65. #define PMD_MASK (~(PMD_SIZE-1))
  66. #define PUD_SIZE (1UL << PUD_SHIFT)
  67. #define PUD_MASK (~(PUD_SIZE-1))
  68. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  69. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  70. /*
  71. * entries per page directory level: the S390 is two-level, so
  72. * we don't really have any PMD directory physically.
  73. * for S390 segment-table entries are combined to one PGD
  74. * that leads to 1024 pte per pgd
  75. */
  76. #define PTRS_PER_PTE 256
  77. #ifndef __s390x__
  78. #define PTRS_PER_PMD 1
  79. #define PTRS_PER_PUD 1
  80. #else /* __s390x__ */
  81. #define PTRS_PER_PMD 2048
  82. #define PTRS_PER_PUD 2048
  83. #endif /* __s390x__ */
  84. #define PTRS_PER_PGD 2048
  85. #define FIRST_USER_ADDRESS 0
  86. #define pte_ERROR(e) \
  87. printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e))
  88. #define pmd_ERROR(e) \
  89. printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e))
  90. #define pud_ERROR(e) \
  91. printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e))
  92. #define pgd_ERROR(e) \
  93. printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e))
  94. #ifndef __ASSEMBLY__
  95. /*
  96. * The vmalloc area will always be on the topmost area of the kernel
  97. * mapping. We reserve 96MB (31bit) / 1GB (64bit) for vmalloc,
  98. * which should be enough for any sane case.
  99. * By putting vmalloc at the top, we maximise the gap between physical
  100. * memory and vmalloc to catch misplaced memory accesses. As a side
  101. * effect, this also makes sure that 64 bit module code cannot be used
  102. * as system call address.
  103. */
  104. #ifndef __s390x__
  105. #define VMALLOC_START 0x78000000UL
  106. #define VMALLOC_END 0x7e000000UL
  107. #define VMEM_MAP_END 0x80000000UL
  108. #else /* __s390x__ */
  109. #define VMALLOC_START 0x3e000000000UL
  110. #define VMALLOC_END 0x3e040000000UL
  111. #define VMEM_MAP_END 0x40000000000UL
  112. #endif /* __s390x__ */
  113. /*
  114. * VMEM_MAX_PHYS is the highest physical address that can be added to the 1:1
  115. * mapping. This needs to be calculated at compile time since the size of the
  116. * VMEM_MAP is static but the size of struct page can change.
  117. */
  118. #define VMEM_MAX_PAGES ((VMEM_MAP_END - VMALLOC_END) / sizeof(struct page))
  119. #define VMEM_MAX_PFN min(VMALLOC_START >> PAGE_SHIFT, VMEM_MAX_PAGES)
  120. #define VMEM_MAX_PHYS ((VMEM_MAX_PFN << PAGE_SHIFT) & ~((16 << 20) - 1))
  121. #define vmemmap ((struct page *) VMALLOC_END)
  122. /*
  123. * A 31 bit pagetable entry of S390 has following format:
  124. * | PFRA | | OS |
  125. * 0 0IP0
  126. * 00000000001111111111222222222233
  127. * 01234567890123456789012345678901
  128. *
  129. * I Page-Invalid Bit: Page is not available for address-translation
  130. * P Page-Protection Bit: Store access not possible for page
  131. *
  132. * A 31 bit segmenttable entry of S390 has following format:
  133. * | P-table origin | |PTL
  134. * 0 IC
  135. * 00000000001111111111222222222233
  136. * 01234567890123456789012345678901
  137. *
  138. * I Segment-Invalid Bit: Segment is not available for address-translation
  139. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  140. * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
  141. *
  142. * The 31 bit segmenttable origin of S390 has following format:
  143. *
  144. * |S-table origin | | STL |
  145. * X **GPS
  146. * 00000000001111111111222222222233
  147. * 01234567890123456789012345678901
  148. *
  149. * X Space-Switch event:
  150. * G Segment-Invalid Bit: *
  151. * P Private-Space Bit: Segment is not private (PoP 3-30)
  152. * S Storage-Alteration:
  153. * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
  154. *
  155. * A 64 bit pagetable entry of S390 has following format:
  156. * | PFRA |0IP0| OS |
  157. * 0000000000111111111122222222223333333333444444444455555555556666
  158. * 0123456789012345678901234567890123456789012345678901234567890123
  159. *
  160. * I Page-Invalid Bit: Page is not available for address-translation
  161. * P Page-Protection Bit: Store access not possible for page
  162. *
  163. * A 64 bit segmenttable entry of S390 has following format:
  164. * | P-table origin | TT
  165. * 0000000000111111111122222222223333333333444444444455555555556666
  166. * 0123456789012345678901234567890123456789012345678901234567890123
  167. *
  168. * I Segment-Invalid Bit: Segment is not available for address-translation
  169. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  170. * P Page-Protection Bit: Store access not possible for page
  171. * TT Type 00
  172. *
  173. * A 64 bit region table entry of S390 has following format:
  174. * | S-table origin | TF TTTL
  175. * 0000000000111111111122222222223333333333444444444455555555556666
  176. * 0123456789012345678901234567890123456789012345678901234567890123
  177. *
  178. * I Segment-Invalid Bit: Segment is not available for address-translation
  179. * TT Type 01
  180. * TF
  181. * TL Table length
  182. *
  183. * The 64 bit regiontable origin of S390 has following format:
  184. * | region table origon | DTTL
  185. * 0000000000111111111122222222223333333333444444444455555555556666
  186. * 0123456789012345678901234567890123456789012345678901234567890123
  187. *
  188. * X Space-Switch event:
  189. * G Segment-Invalid Bit:
  190. * P Private-Space Bit:
  191. * S Storage-Alteration:
  192. * R Real space
  193. * TL Table-Length:
  194. *
  195. * A storage key has the following format:
  196. * | ACC |F|R|C|0|
  197. * 0 3 4 5 6 7
  198. * ACC: access key
  199. * F : fetch protection bit
  200. * R : referenced bit
  201. * C : changed bit
  202. */
  203. /* Hardware bits in the page table entry */
  204. #define _PAGE_RO 0x200 /* HW read-only bit */
  205. #define _PAGE_INVALID 0x400 /* HW invalid bit */
  206. /* Software bits in the page table entry */
  207. #define _PAGE_SWT 0x001 /* SW pte type bit t */
  208. #define _PAGE_SWX 0x002 /* SW pte type bit x */
  209. #define _PAGE_SPECIAL 0x004 /* SW associated with special page */
  210. #define __HAVE_ARCH_PTE_SPECIAL
  211. /* Set of bits not changed in pte_modify */
  212. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL)
  213. /* Six different types of pages. */
  214. #define _PAGE_TYPE_EMPTY 0x400
  215. #define _PAGE_TYPE_NONE 0x401
  216. #define _PAGE_TYPE_SWAP 0x403
  217. #define _PAGE_TYPE_FILE 0x601 /* bit 0x002 is used for offset !! */
  218. #define _PAGE_TYPE_RO 0x200
  219. #define _PAGE_TYPE_RW 0x000
  220. #define _PAGE_TYPE_EX_RO 0x202
  221. #define _PAGE_TYPE_EX_RW 0x002
  222. /*
  223. * Only four types for huge pages, using the invalid bit and protection bit
  224. * of a segment table entry.
  225. */
  226. #define _HPAGE_TYPE_EMPTY 0x020 /* _SEGMENT_ENTRY_INV */
  227. #define _HPAGE_TYPE_NONE 0x220
  228. #define _HPAGE_TYPE_RO 0x200 /* _SEGMENT_ENTRY_RO */
  229. #define _HPAGE_TYPE_RW 0x000
  230. /*
  231. * PTE type bits are rather complicated. handle_pte_fault uses pte_present,
  232. * pte_none and pte_file to find out the pte type WITHOUT holding the page
  233. * table lock. ptep_clear_flush on the other hand uses ptep_clear_flush to
  234. * invalidate a given pte. ipte sets the hw invalid bit and clears all tlbs
  235. * for the page. The page table entry is set to _PAGE_TYPE_EMPTY afterwards.
  236. * This change is done while holding the lock, but the intermediate step
  237. * of a previously valid pte with the hw invalid bit set can be observed by
  238. * handle_pte_fault. That makes it necessary that all valid pte types with
  239. * the hw invalid bit set must be distinguishable from the four pte types
  240. * empty, none, swap and file.
  241. *
  242. * irxt ipte irxt
  243. * _PAGE_TYPE_EMPTY 1000 -> 1000
  244. * _PAGE_TYPE_NONE 1001 -> 1001
  245. * _PAGE_TYPE_SWAP 1011 -> 1011
  246. * _PAGE_TYPE_FILE 11?1 -> 11?1
  247. * _PAGE_TYPE_RO 0100 -> 1100
  248. * _PAGE_TYPE_RW 0000 -> 1000
  249. * _PAGE_TYPE_EX_RO 0110 -> 1110
  250. * _PAGE_TYPE_EX_RW 0010 -> 1010
  251. *
  252. * pte_none is true for bits combinations 1000, 1010, 1100, 1110
  253. * pte_present is true for bits combinations 0000, 0010, 0100, 0110, 1001
  254. * pte_file is true for bits combinations 1101, 1111
  255. * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
  256. */
  257. /* Page status table bits for virtualization */
  258. #define RCP_PCL_BIT 55
  259. #define RCP_HR_BIT 54
  260. #define RCP_HC_BIT 53
  261. #define RCP_GR_BIT 50
  262. #define RCP_GC_BIT 49
  263. /* User dirty bit for KVM's migration feature */
  264. #define KVM_UD_BIT 47
  265. #ifndef __s390x__
  266. /* Bits in the segment table address-space-control-element */
  267. #define _ASCE_SPACE_SWITCH 0x80000000UL /* space switch event */
  268. #define _ASCE_ORIGIN_MASK 0x7ffff000UL /* segment table origin */
  269. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  270. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  271. #define _ASCE_TABLE_LENGTH 0x7f /* 128 x 64 entries = 8k */
  272. /* Bits in the segment table entry */
  273. #define _SEGMENT_ENTRY_ORIGIN 0x7fffffc0UL /* page table origin */
  274. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  275. #define _SEGMENT_ENTRY_COMMON 0x10 /* common segment bit */
  276. #define _SEGMENT_ENTRY_PTL 0x0f /* page table length */
  277. #define _SEGMENT_ENTRY (_SEGMENT_ENTRY_PTL)
  278. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  279. #else /* __s390x__ */
  280. /* Bits in the segment/region table address-space-control-element */
  281. #define _ASCE_ORIGIN ~0xfffUL/* segment table origin */
  282. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  283. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  284. #define _ASCE_SPACE_SWITCH 0x40 /* space switch event */
  285. #define _ASCE_REAL_SPACE 0x20 /* real space control */
  286. #define _ASCE_TYPE_MASK 0x0c /* asce table type mask */
  287. #define _ASCE_TYPE_REGION1 0x0c /* region first table type */
  288. #define _ASCE_TYPE_REGION2 0x08 /* region second table type */
  289. #define _ASCE_TYPE_REGION3 0x04 /* region third table type */
  290. #define _ASCE_TYPE_SEGMENT 0x00 /* segment table type */
  291. #define _ASCE_TABLE_LENGTH 0x03 /* region table length */
  292. /* Bits in the region table entry */
  293. #define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */
  294. #define _REGION_ENTRY_INV 0x20 /* invalid region table entry */
  295. #define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */
  296. #define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */
  297. #define _REGION_ENTRY_TYPE_R2 0x08 /* region second table type */
  298. #define _REGION_ENTRY_TYPE_R3 0x04 /* region third table type */
  299. #define _REGION_ENTRY_LENGTH 0x03 /* region third length */
  300. #define _REGION1_ENTRY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_LENGTH)
  301. #define _REGION1_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INV)
  302. #define _REGION2_ENTRY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_LENGTH)
  303. #define _REGION2_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INV)
  304. #define _REGION3_ENTRY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_LENGTH)
  305. #define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INV)
  306. /* Bits in the segment table entry */
  307. #define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL/* segment table origin */
  308. #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */
  309. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  310. #define _SEGMENT_ENTRY (0)
  311. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  312. #define _SEGMENT_ENTRY_LARGE 0x400 /* STE-format control, large page */
  313. #define _SEGMENT_ENTRY_CO 0x100 /* change-recording override */
  314. #endif /* __s390x__ */
  315. /*
  316. * A user page table pointer has the space-switch-event bit, the
  317. * private-space-control bit and the storage-alteration-event-control
  318. * bit set. A kernel page table pointer doesn't need them.
  319. */
  320. #define _ASCE_USER_BITS (_ASCE_SPACE_SWITCH | _ASCE_PRIVATE_SPACE | \
  321. _ASCE_ALT_EVENT)
  322. /* Bits int the storage key */
  323. #define _PAGE_CHANGED 0x02 /* HW changed bit */
  324. #define _PAGE_REFERENCED 0x04 /* HW referenced bit */
  325. /*
  326. * Page protection definitions.
  327. */
  328. #define PAGE_NONE __pgprot(_PAGE_TYPE_NONE)
  329. #define PAGE_RO __pgprot(_PAGE_TYPE_RO)
  330. #define PAGE_RW __pgprot(_PAGE_TYPE_RW)
  331. #define PAGE_EX_RO __pgprot(_PAGE_TYPE_EX_RO)
  332. #define PAGE_EX_RW __pgprot(_PAGE_TYPE_EX_RW)
  333. #define PAGE_KERNEL PAGE_RW
  334. #define PAGE_COPY PAGE_RO
  335. /*
  336. * Dependent on the EXEC_PROTECT option s390 can do execute protection.
  337. * Write permission always implies read permission. In theory with a
  338. * primary/secondary page table execute only can be implemented but
  339. * it would cost an additional bit in the pte to distinguish all the
  340. * different pte types. To avoid that execute permission currently
  341. * implies read permission as well.
  342. */
  343. /*xwr*/
  344. #define __P000 PAGE_NONE
  345. #define __P001 PAGE_RO
  346. #define __P010 PAGE_RO
  347. #define __P011 PAGE_RO
  348. #define __P100 PAGE_EX_RO
  349. #define __P101 PAGE_EX_RO
  350. #define __P110 PAGE_EX_RO
  351. #define __P111 PAGE_EX_RO
  352. #define __S000 PAGE_NONE
  353. #define __S001 PAGE_RO
  354. #define __S010 PAGE_RW
  355. #define __S011 PAGE_RW
  356. #define __S100 PAGE_EX_RO
  357. #define __S101 PAGE_EX_RO
  358. #define __S110 PAGE_EX_RW
  359. #define __S111 PAGE_EX_RW
  360. #ifndef __s390x__
  361. # define PxD_SHADOW_SHIFT 1
  362. #else /* __s390x__ */
  363. # define PxD_SHADOW_SHIFT 2
  364. #endif /* __s390x__ */
  365. static inline void *get_shadow_table(void *table)
  366. {
  367. unsigned long addr, offset;
  368. struct page *page;
  369. addr = (unsigned long) table;
  370. offset = addr & ((PAGE_SIZE << PxD_SHADOW_SHIFT) - 1);
  371. page = virt_to_page((void *)(addr ^ offset));
  372. return (void *)(addr_t)(page->index ? (page->index | offset) : 0UL);
  373. }
  374. /*
  375. * Certain architectures need to do special things when PTEs
  376. * within a page table are directly modified. Thus, the following
  377. * hook is made available.
  378. */
  379. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  380. pte_t *ptep, pte_t entry)
  381. {
  382. *ptep = entry;
  383. if (mm->context.noexec) {
  384. if (!(pte_val(entry) & _PAGE_INVALID) &&
  385. (pte_val(entry) & _PAGE_SWX))
  386. pte_val(entry) |= _PAGE_RO;
  387. else
  388. pte_val(entry) = _PAGE_TYPE_EMPTY;
  389. ptep[PTRS_PER_PTE] = entry;
  390. }
  391. }
  392. /*
  393. * pgd/pmd/pte query functions
  394. */
  395. #ifndef __s390x__
  396. static inline int pgd_present(pgd_t pgd) { return 1; }
  397. static inline int pgd_none(pgd_t pgd) { return 0; }
  398. static inline int pgd_bad(pgd_t pgd) { return 0; }
  399. static inline int pud_present(pud_t pud) { return 1; }
  400. static inline int pud_none(pud_t pud) { return 0; }
  401. static inline int pud_bad(pud_t pud) { return 0; }
  402. #else /* __s390x__ */
  403. static inline int pgd_present(pgd_t pgd)
  404. {
  405. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  406. return 1;
  407. return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL;
  408. }
  409. static inline int pgd_none(pgd_t pgd)
  410. {
  411. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  412. return 0;
  413. return (pgd_val(pgd) & _REGION_ENTRY_INV) != 0UL;
  414. }
  415. static inline int pgd_bad(pgd_t pgd)
  416. {
  417. /*
  418. * With dynamic page table levels the pgd can be a region table
  419. * entry or a segment table entry. Check for the bit that are
  420. * invalid for either table entry.
  421. */
  422. unsigned long mask =
  423. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV &
  424. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  425. return (pgd_val(pgd) & mask) != 0;
  426. }
  427. static inline int pud_present(pud_t pud)
  428. {
  429. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  430. return 1;
  431. return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL;
  432. }
  433. static inline int pud_none(pud_t pud)
  434. {
  435. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  436. return 0;
  437. return (pud_val(pud) & _REGION_ENTRY_INV) != 0UL;
  438. }
  439. static inline int pud_bad(pud_t pud)
  440. {
  441. /*
  442. * With dynamic page table levels the pud can be a region table
  443. * entry or a segment table entry. Check for the bit that are
  444. * invalid for either table entry.
  445. */
  446. unsigned long mask =
  447. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INV &
  448. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  449. return (pud_val(pud) & mask) != 0;
  450. }
  451. #endif /* __s390x__ */
  452. static inline int pmd_present(pmd_t pmd)
  453. {
  454. return (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) != 0UL;
  455. }
  456. static inline int pmd_none(pmd_t pmd)
  457. {
  458. return (pmd_val(pmd) & _SEGMENT_ENTRY_INV) != 0UL;
  459. }
  460. static inline int pmd_bad(pmd_t pmd)
  461. {
  462. unsigned long mask = ~_SEGMENT_ENTRY_ORIGIN & ~_SEGMENT_ENTRY_INV;
  463. return (pmd_val(pmd) & mask) != _SEGMENT_ENTRY;
  464. }
  465. static inline int pte_none(pte_t pte)
  466. {
  467. return (pte_val(pte) & _PAGE_INVALID) && !(pte_val(pte) & _PAGE_SWT);
  468. }
  469. static inline int pte_present(pte_t pte)
  470. {
  471. unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT | _PAGE_SWX;
  472. return (pte_val(pte) & mask) == _PAGE_TYPE_NONE ||
  473. (!(pte_val(pte) & _PAGE_INVALID) &&
  474. !(pte_val(pte) & _PAGE_SWT));
  475. }
  476. static inline int pte_file(pte_t pte)
  477. {
  478. unsigned long mask = _PAGE_RO | _PAGE_INVALID | _PAGE_SWT;
  479. return (pte_val(pte) & mask) == _PAGE_TYPE_FILE;
  480. }
  481. static inline int pte_special(pte_t pte)
  482. {
  483. return (pte_val(pte) & _PAGE_SPECIAL);
  484. }
  485. #define __HAVE_ARCH_PTE_SAME
  486. #define pte_same(a,b) (pte_val(a) == pte_val(b))
  487. static inline void rcp_lock(pte_t *ptep)
  488. {
  489. #ifdef CONFIG_PGSTE
  490. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  491. preempt_disable();
  492. while (test_and_set_bit(RCP_PCL_BIT, pgste))
  493. ;
  494. #endif
  495. }
  496. static inline void rcp_unlock(pte_t *ptep)
  497. {
  498. #ifdef CONFIG_PGSTE
  499. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  500. clear_bit(RCP_PCL_BIT, pgste);
  501. preempt_enable();
  502. #endif
  503. }
  504. /* forward declaration for SetPageUptodate in page-flags.h*/
  505. static inline void page_clear_dirty(struct page *page);
  506. #include <linux/page-flags.h>
  507. static inline void ptep_rcp_copy(pte_t *ptep)
  508. {
  509. #ifdef CONFIG_PGSTE
  510. struct page *page = virt_to_page(pte_val(*ptep));
  511. unsigned int skey;
  512. unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  513. skey = page_get_storage_key(page_to_phys(page));
  514. if (skey & _PAGE_CHANGED) {
  515. set_bit_simple(RCP_GC_BIT, pgste);
  516. set_bit_simple(KVM_UD_BIT, pgste);
  517. }
  518. if (skey & _PAGE_REFERENCED)
  519. set_bit_simple(RCP_GR_BIT, pgste);
  520. if (test_and_clear_bit_simple(RCP_HC_BIT, pgste)) {
  521. SetPageDirty(page);
  522. set_bit_simple(KVM_UD_BIT, pgste);
  523. }
  524. if (test_and_clear_bit_simple(RCP_HR_BIT, pgste))
  525. SetPageReferenced(page);
  526. #endif
  527. }
  528. /*
  529. * query functions pte_write/pte_dirty/pte_young only work if
  530. * pte_present() is true. Undefined behaviour if not..
  531. */
  532. static inline int pte_write(pte_t pte)
  533. {
  534. return (pte_val(pte) & _PAGE_RO) == 0;
  535. }
  536. static inline int pte_dirty(pte_t pte)
  537. {
  538. /* A pte is neither clean nor dirty on s/390. The dirty bit
  539. * is in the storage key. See page_test_and_clear_dirty for
  540. * details.
  541. */
  542. return 0;
  543. }
  544. static inline int pte_young(pte_t pte)
  545. {
  546. /* A pte is neither young nor old on s/390. The young bit
  547. * is in the storage key. See page_test_and_clear_young for
  548. * details.
  549. */
  550. return 0;
  551. }
  552. /*
  553. * pgd/pmd/pte modification functions
  554. */
  555. #ifndef __s390x__
  556. #define pgd_clear(pgd) do { } while (0)
  557. #define pud_clear(pud) do { } while (0)
  558. #else /* __s390x__ */
  559. static inline void pgd_clear_kernel(pgd_t * pgd)
  560. {
  561. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  562. pgd_val(*pgd) = _REGION2_ENTRY_EMPTY;
  563. }
  564. static inline void pgd_clear(pgd_t * pgd)
  565. {
  566. pgd_t *shadow = get_shadow_table(pgd);
  567. pgd_clear_kernel(pgd);
  568. if (shadow)
  569. pgd_clear_kernel(shadow);
  570. }
  571. static inline void pud_clear_kernel(pud_t *pud)
  572. {
  573. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  574. pud_val(*pud) = _REGION3_ENTRY_EMPTY;
  575. }
  576. static inline void pud_clear(pud_t *pud)
  577. {
  578. pud_t *shadow = get_shadow_table(pud);
  579. pud_clear_kernel(pud);
  580. if (shadow)
  581. pud_clear_kernel(shadow);
  582. }
  583. #endif /* __s390x__ */
  584. static inline void pmd_clear_kernel(pmd_t * pmdp)
  585. {
  586. pmd_val(*pmdp) = _SEGMENT_ENTRY_EMPTY;
  587. }
  588. static inline void pmd_clear(pmd_t *pmd)
  589. {
  590. pmd_t *shadow = get_shadow_table(pmd);
  591. pmd_clear_kernel(pmd);
  592. if (shadow)
  593. pmd_clear_kernel(shadow);
  594. }
  595. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  596. {
  597. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  598. if (mm->context.noexec)
  599. pte_val(ptep[PTRS_PER_PTE]) = _PAGE_TYPE_EMPTY;
  600. }
  601. /*
  602. * The following pte modification functions only work if
  603. * pte_present() is true. Undefined behaviour if not..
  604. */
  605. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  606. {
  607. pte_val(pte) &= _PAGE_CHG_MASK;
  608. pte_val(pte) |= pgprot_val(newprot);
  609. return pte;
  610. }
  611. static inline pte_t pte_wrprotect(pte_t pte)
  612. {
  613. /* Do not clobber _PAGE_TYPE_NONE pages! */
  614. if (!(pte_val(pte) & _PAGE_INVALID))
  615. pte_val(pte) |= _PAGE_RO;
  616. return pte;
  617. }
  618. static inline pte_t pte_mkwrite(pte_t pte)
  619. {
  620. pte_val(pte) &= ~_PAGE_RO;
  621. return pte;
  622. }
  623. static inline pte_t pte_mkclean(pte_t pte)
  624. {
  625. /* The only user of pte_mkclean is the fork() code.
  626. We must *not* clear the *physical* page dirty bit
  627. just because fork() wants to clear the dirty bit in
  628. *one* of the page's mappings. So we just do nothing. */
  629. return pte;
  630. }
  631. static inline pte_t pte_mkdirty(pte_t pte)
  632. {
  633. /* We do not explicitly set the dirty bit because the
  634. * sske instruction is slow. It is faster to let the
  635. * next instruction set the dirty bit.
  636. */
  637. return pte;
  638. }
  639. static inline pte_t pte_mkold(pte_t pte)
  640. {
  641. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  642. * There is no point in clearing the real referenced bit.
  643. */
  644. return pte;
  645. }
  646. static inline pte_t pte_mkyoung(pte_t pte)
  647. {
  648. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  649. * There is no point in setting the real referenced bit.
  650. */
  651. return pte;
  652. }
  653. static inline pte_t pte_mkspecial(pte_t pte)
  654. {
  655. pte_val(pte) |= _PAGE_SPECIAL;
  656. return pte;
  657. }
  658. #ifdef CONFIG_PGSTE
  659. /*
  660. * Get (and clear) the user dirty bit for a PTE.
  661. */
  662. static inline int kvm_s390_test_and_clear_page_dirty(struct mm_struct *mm,
  663. pte_t *ptep)
  664. {
  665. int dirty;
  666. unsigned long *pgste;
  667. struct page *page;
  668. unsigned int skey;
  669. if (!mm->context.has_pgste)
  670. return -EINVAL;
  671. rcp_lock(ptep);
  672. pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  673. page = virt_to_page(pte_val(*ptep));
  674. skey = page_get_storage_key(page_to_phys(page));
  675. if (skey & _PAGE_CHANGED) {
  676. set_bit_simple(RCP_GC_BIT, pgste);
  677. set_bit_simple(KVM_UD_BIT, pgste);
  678. }
  679. if (test_and_clear_bit_simple(RCP_HC_BIT, pgste)) {
  680. SetPageDirty(page);
  681. set_bit_simple(KVM_UD_BIT, pgste);
  682. }
  683. dirty = test_and_clear_bit_simple(KVM_UD_BIT, pgste);
  684. if (skey & _PAGE_CHANGED)
  685. page_clear_dirty(page);
  686. rcp_unlock(ptep);
  687. return dirty;
  688. }
  689. #endif
  690. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  691. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  692. unsigned long addr, pte_t *ptep)
  693. {
  694. #ifdef CONFIG_PGSTE
  695. unsigned long physpage;
  696. int young;
  697. unsigned long *pgste;
  698. if (!vma->vm_mm->context.has_pgste)
  699. return 0;
  700. physpage = pte_val(*ptep) & PAGE_MASK;
  701. pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  702. young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
  703. rcp_lock(ptep);
  704. if (young)
  705. set_bit_simple(RCP_GR_BIT, pgste);
  706. young |= test_and_clear_bit_simple(RCP_HR_BIT, pgste);
  707. rcp_unlock(ptep);
  708. return young;
  709. #endif
  710. return 0;
  711. }
  712. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  713. static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  714. unsigned long address, pte_t *ptep)
  715. {
  716. /* No need to flush TLB
  717. * On s390 reference bits are in storage key and never in TLB
  718. * With virtualization we handle the reference bit, without we
  719. * we can simply return */
  720. #ifdef CONFIG_PGSTE
  721. return ptep_test_and_clear_young(vma, address, ptep);
  722. #endif
  723. return 0;
  724. }
  725. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  726. {
  727. if (!(pte_val(*ptep) & _PAGE_INVALID)) {
  728. #ifndef __s390x__
  729. /* pto must point to the start of the segment table */
  730. pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
  731. #else
  732. /* ipte in zarch mode can do the math */
  733. pte_t *pto = ptep;
  734. #endif
  735. asm volatile(
  736. " ipte %2,%3"
  737. : "=m" (*ptep) : "m" (*ptep),
  738. "a" (pto), "a" (address));
  739. }
  740. }
  741. static inline void ptep_invalidate(struct mm_struct *mm,
  742. unsigned long address, pte_t *ptep)
  743. {
  744. if (mm->context.has_pgste) {
  745. rcp_lock(ptep);
  746. __ptep_ipte(address, ptep);
  747. ptep_rcp_copy(ptep);
  748. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  749. rcp_unlock(ptep);
  750. return;
  751. }
  752. __ptep_ipte(address, ptep);
  753. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  754. if (mm->context.noexec) {
  755. __ptep_ipte(address, ptep + PTRS_PER_PTE);
  756. pte_val(*(ptep + PTRS_PER_PTE)) = _PAGE_TYPE_EMPTY;
  757. }
  758. }
  759. /*
  760. * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
  761. * both clear the TLB for the unmapped pte. The reason is that
  762. * ptep_get_and_clear is used in common code (e.g. change_pte_range)
  763. * to modify an active pte. The sequence is
  764. * 1) ptep_get_and_clear
  765. * 2) set_pte_at
  766. * 3) flush_tlb_range
  767. * On s390 the tlb needs to get flushed with the modification of the pte
  768. * if the pte is active. The only way how this can be implemented is to
  769. * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range
  770. * is a nop.
  771. */
  772. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  773. #define ptep_get_and_clear(__mm, __address, __ptep) \
  774. ({ \
  775. pte_t __pte = *(__ptep); \
  776. if (atomic_read(&(__mm)->mm_users) > 1 || \
  777. (__mm) != current->active_mm) \
  778. ptep_invalidate(__mm, __address, __ptep); \
  779. else \
  780. pte_clear((__mm), (__address), (__ptep)); \
  781. __pte; \
  782. })
  783. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  784. static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
  785. unsigned long address, pte_t *ptep)
  786. {
  787. pte_t pte = *ptep;
  788. ptep_invalidate(vma->vm_mm, address, ptep);
  789. return pte;
  790. }
  791. /*
  792. * The batched pte unmap code uses ptep_get_and_clear_full to clear the
  793. * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
  794. * tlbs of an mm if it can guarantee that the ptes of the mm_struct
  795. * cannot be accessed while the batched unmap is running. In this case
  796. * full==1 and a simple pte_clear is enough. See tlb.h.
  797. */
  798. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  799. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  800. unsigned long addr,
  801. pte_t *ptep, int full)
  802. {
  803. pte_t pte = *ptep;
  804. if (full)
  805. pte_clear(mm, addr, ptep);
  806. else
  807. ptep_invalidate(mm, addr, ptep);
  808. return pte;
  809. }
  810. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  811. #define ptep_set_wrprotect(__mm, __addr, __ptep) \
  812. ({ \
  813. pte_t __pte = *(__ptep); \
  814. if (pte_write(__pte)) { \
  815. if (atomic_read(&(__mm)->mm_users) > 1 || \
  816. (__mm) != current->active_mm) \
  817. ptep_invalidate(__mm, __addr, __ptep); \
  818. set_pte_at(__mm, __addr, __ptep, pte_wrprotect(__pte)); \
  819. } \
  820. })
  821. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  822. #define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
  823. ({ \
  824. int __changed = !pte_same(*(__ptep), __entry); \
  825. if (__changed) { \
  826. ptep_invalidate((__vma)->vm_mm, __addr, __ptep); \
  827. set_pte_at((__vma)->vm_mm, __addr, __ptep, __entry); \
  828. } \
  829. __changed; \
  830. })
  831. /*
  832. * Test and clear dirty bit in storage key.
  833. * We can't clear the changed bit atomically. This is a potential
  834. * race against modification of the referenced bit. This function
  835. * should therefore only be called if it is not mapped in any
  836. * address space.
  837. */
  838. #define __HAVE_ARCH_PAGE_TEST_DIRTY
  839. static inline int page_test_dirty(struct page *page)
  840. {
  841. return (page_get_storage_key(page_to_phys(page)) & _PAGE_CHANGED) != 0;
  842. }
  843. #define __HAVE_ARCH_PAGE_CLEAR_DIRTY
  844. static inline void page_clear_dirty(struct page *page)
  845. {
  846. page_set_storage_key(page_to_phys(page), PAGE_DEFAULT_KEY);
  847. }
  848. /*
  849. * Test and clear referenced bit in storage key.
  850. */
  851. #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
  852. static inline int page_test_and_clear_young(struct page *page)
  853. {
  854. unsigned long physpage = page_to_phys(page);
  855. int ccode;
  856. asm volatile(
  857. " rrbe 0,%1\n"
  858. " ipm %0\n"
  859. " srl %0,28\n"
  860. : "=d" (ccode) : "a" (physpage) : "cc" );
  861. return ccode & 2;
  862. }
  863. /*
  864. * Conversion functions: convert a page and protection to a page entry,
  865. * and a page entry and page directory to the page they refer to.
  866. */
  867. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  868. {
  869. pte_t __pte;
  870. pte_val(__pte) = physpage + pgprot_val(pgprot);
  871. return __pte;
  872. }
  873. static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
  874. {
  875. unsigned long physpage = page_to_phys(page);
  876. return mk_pte_phys(physpage, pgprot);
  877. }
  878. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  879. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  880. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  881. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  882. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  883. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  884. #ifndef __s390x__
  885. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  886. #define pud_deref(pmd) ({ BUG(); 0UL; })
  887. #define pgd_deref(pmd) ({ BUG(); 0UL; })
  888. #define pud_offset(pgd, address) ((pud_t *) pgd)
  889. #define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address))
  890. #else /* __s390x__ */
  891. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  892. #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
  893. #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
  894. static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  895. {
  896. pud_t *pud = (pud_t *) pgd;
  897. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  898. pud = (pud_t *) pgd_deref(*pgd);
  899. return pud + pud_index(address);
  900. }
  901. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  902. {
  903. pmd_t *pmd = (pmd_t *) pud;
  904. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  905. pmd = (pmd_t *) pud_deref(*pud);
  906. return pmd + pmd_index(address);
  907. }
  908. #endif /* __s390x__ */
  909. #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))
  910. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  911. #define pte_page(x) pfn_to_page(pte_pfn(x))
  912. #define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
  913. /* Find an entry in the lowest level page table.. */
  914. #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
  915. #define pte_offset_kernel(pmd, address) pte_offset(pmd,address)
  916. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  917. #define pte_offset_map_nested(pmd, address) pte_offset_kernel(pmd, address)
  918. #define pte_unmap(pte) do { } while (0)
  919. #define pte_unmap_nested(pte) do { } while (0)
  920. /*
  921. * 31 bit swap entry format:
  922. * A page-table entry has some bits we have to treat in a special way.
  923. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  924. * exception will occur instead of a page translation exception. The
  925. * specifiation exception has the bad habit not to store necessary
  926. * information in the lowcore.
  927. * Bit 21 and bit 22 are the page invalid bit and the page protection
  928. * bit. We set both to indicate a swapped page.
  929. * Bit 30 and 31 are used to distinguish the different page types. For
  930. * a swapped page these bits need to be zero.
  931. * This leaves the bits 1-19 and bits 24-29 to store type and offset.
  932. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
  933. * plus 24 for the offset.
  934. * 0| offset |0110|o|type |00|
  935. * 0 0000000001111111111 2222 2 22222 33
  936. * 0 1234567890123456789 0123 4 56789 01
  937. *
  938. * 64 bit swap entry format:
  939. * A page-table entry has some bits we have to treat in a special way.
  940. * Bits 52 and bit 55 have to be zero, otherwise an specification
  941. * exception will occur instead of a page translation exception. The
  942. * specifiation exception has the bad habit not to store necessary
  943. * information in the lowcore.
  944. * Bit 53 and bit 54 are the page invalid bit and the page protection
  945. * bit. We set both to indicate a swapped page.
  946. * Bit 62 and 63 are used to distinguish the different page types. For
  947. * a swapped page these bits need to be zero.
  948. * This leaves the bits 0-51 and bits 56-61 to store type and offset.
  949. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51
  950. * plus 56 for the offset.
  951. * | offset |0110|o|type |00|
  952. * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66
  953. * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23
  954. */
  955. #ifndef __s390x__
  956. #define __SWP_OFFSET_MASK (~0UL >> 12)
  957. #else
  958. #define __SWP_OFFSET_MASK (~0UL >> 11)
  959. #endif
  960. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  961. {
  962. pte_t pte;
  963. offset &= __SWP_OFFSET_MASK;
  964. pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) |
  965. ((offset & 1UL) << 7) | ((offset & ~1UL) << 11);
  966. return pte;
  967. }
  968. #define __swp_type(entry) (((entry).val >> 2) & 0x1f)
  969. #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))
  970. #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  971. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  972. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  973. #ifndef __s390x__
  974. # define PTE_FILE_MAX_BITS 26
  975. #else /* __s390x__ */
  976. # define PTE_FILE_MAX_BITS 59
  977. #endif /* __s390x__ */
  978. #define pte_to_pgoff(__pte) \
  979. ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))
  980. #define pgoff_to_pte(__off) \
  981. ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \
  982. | _PAGE_TYPE_FILE })
  983. #endif /* !__ASSEMBLY__ */
  984. #define kern_addr_valid(addr) (1)
  985. extern int vmem_add_mapping(unsigned long start, unsigned long size);
  986. extern int vmem_remove_mapping(unsigned long start, unsigned long size);
  987. extern int s390_enable_sie(void);
  988. /*
  989. * No page table caches to initialise
  990. */
  991. #define pgtable_cache_init() do { } while (0)
  992. #include <asm-generic/pgtable.h>
  993. #endif /* _S390_PAGE_H */