pgtable.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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. if (mm->context.pgstes)
  598. ptep_rcp_copy(ptep);
  599. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  600. if (mm->context.noexec)
  601. pte_val(ptep[PTRS_PER_PTE]) = _PAGE_TYPE_EMPTY;
  602. }
  603. /*
  604. * The following pte modification functions only work if
  605. * pte_present() is true. Undefined behaviour if not..
  606. */
  607. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  608. {
  609. pte_val(pte) &= _PAGE_CHG_MASK;
  610. pte_val(pte) |= pgprot_val(newprot);
  611. return pte;
  612. }
  613. static inline pte_t pte_wrprotect(pte_t pte)
  614. {
  615. /* Do not clobber _PAGE_TYPE_NONE pages! */
  616. if (!(pte_val(pte) & _PAGE_INVALID))
  617. pte_val(pte) |= _PAGE_RO;
  618. return pte;
  619. }
  620. static inline pte_t pte_mkwrite(pte_t pte)
  621. {
  622. pte_val(pte) &= ~_PAGE_RO;
  623. return pte;
  624. }
  625. static inline pte_t pte_mkclean(pte_t pte)
  626. {
  627. /* The only user of pte_mkclean is the fork() code.
  628. We must *not* clear the *physical* page dirty bit
  629. just because fork() wants to clear the dirty bit in
  630. *one* of the page's mappings. So we just do nothing. */
  631. return pte;
  632. }
  633. static inline pte_t pte_mkdirty(pte_t pte)
  634. {
  635. /* We do not explicitly set the dirty bit because the
  636. * sske instruction is slow. It is faster to let the
  637. * next instruction set the dirty bit.
  638. */
  639. return pte;
  640. }
  641. static inline pte_t pte_mkold(pte_t pte)
  642. {
  643. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  644. * There is no point in clearing the real referenced bit.
  645. */
  646. return pte;
  647. }
  648. static inline pte_t pte_mkyoung(pte_t pte)
  649. {
  650. /* S/390 doesn't keep its dirty/referenced bit in the pte.
  651. * There is no point in setting the real referenced bit.
  652. */
  653. return pte;
  654. }
  655. static inline pte_t pte_mkspecial(pte_t pte)
  656. {
  657. pte_val(pte) |= _PAGE_SPECIAL;
  658. return pte;
  659. }
  660. #ifdef CONFIG_PGSTE
  661. /*
  662. * Get (and clear) the user dirty bit for a PTE.
  663. */
  664. static inline int kvm_s390_test_and_clear_page_dirty(struct mm_struct *mm,
  665. pte_t *ptep)
  666. {
  667. int dirty;
  668. unsigned long *pgste;
  669. struct page *page;
  670. unsigned int skey;
  671. if (!mm->context.pgstes)
  672. return -EINVAL;
  673. rcp_lock(ptep);
  674. pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  675. page = virt_to_page(pte_val(*ptep));
  676. skey = page_get_storage_key(page_to_phys(page));
  677. if (skey & _PAGE_CHANGED) {
  678. set_bit_simple(RCP_GC_BIT, pgste);
  679. set_bit_simple(KVM_UD_BIT, pgste);
  680. }
  681. if (test_and_clear_bit_simple(RCP_HC_BIT, pgste)) {
  682. SetPageDirty(page);
  683. set_bit_simple(KVM_UD_BIT, pgste);
  684. }
  685. dirty = test_and_clear_bit_simple(KVM_UD_BIT, pgste);
  686. if (skey & _PAGE_CHANGED)
  687. page_clear_dirty(page);
  688. rcp_unlock(ptep);
  689. return dirty;
  690. }
  691. #endif
  692. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  693. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  694. unsigned long addr, pte_t *ptep)
  695. {
  696. #ifdef CONFIG_PGSTE
  697. unsigned long physpage;
  698. int young;
  699. unsigned long *pgste;
  700. if (!vma->vm_mm->context.pgstes)
  701. return 0;
  702. physpage = pte_val(*ptep) & PAGE_MASK;
  703. pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
  704. young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
  705. rcp_lock(ptep);
  706. if (young)
  707. set_bit_simple(RCP_GR_BIT, pgste);
  708. young |= test_and_clear_bit_simple(RCP_HR_BIT, pgste);
  709. rcp_unlock(ptep);
  710. return young;
  711. #endif
  712. return 0;
  713. }
  714. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  715. static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  716. unsigned long address, pte_t *ptep)
  717. {
  718. /* No need to flush TLB
  719. * On s390 reference bits are in storage key and never in TLB
  720. * With virtualization we handle the reference bit, without we
  721. * we can simply return */
  722. #ifdef CONFIG_PGSTE
  723. return ptep_test_and_clear_young(vma, address, ptep);
  724. #endif
  725. return 0;
  726. }
  727. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  728. {
  729. if (!(pte_val(*ptep) & _PAGE_INVALID)) {
  730. #ifndef __s390x__
  731. /* pto must point to the start of the segment table */
  732. pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
  733. #else
  734. /* ipte in zarch mode can do the math */
  735. pte_t *pto = ptep;
  736. #endif
  737. asm volatile(
  738. " ipte %2,%3"
  739. : "=m" (*ptep) : "m" (*ptep),
  740. "a" (pto), "a" (address));
  741. }
  742. }
  743. static inline void ptep_invalidate(struct mm_struct *mm,
  744. unsigned long address, pte_t *ptep)
  745. {
  746. if (mm->context.pgstes) {
  747. rcp_lock(ptep);
  748. __ptep_ipte(address, ptep);
  749. ptep_rcp_copy(ptep);
  750. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  751. rcp_unlock(ptep);
  752. return;
  753. }
  754. __ptep_ipte(address, ptep);
  755. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  756. if (mm->context.noexec) {
  757. __ptep_ipte(address, ptep + PTRS_PER_PTE);
  758. pte_val(*(ptep + PTRS_PER_PTE)) = _PAGE_TYPE_EMPTY;
  759. }
  760. }
  761. /*
  762. * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
  763. * both clear the TLB for the unmapped pte. The reason is that
  764. * ptep_get_and_clear is used in common code (e.g. change_pte_range)
  765. * to modify an active pte. The sequence is
  766. * 1) ptep_get_and_clear
  767. * 2) set_pte_at
  768. * 3) flush_tlb_range
  769. * On s390 the tlb needs to get flushed with the modification of the pte
  770. * if the pte is active. The only way how this can be implemented is to
  771. * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range
  772. * is a nop.
  773. */
  774. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  775. #define ptep_get_and_clear(__mm, __address, __ptep) \
  776. ({ \
  777. pte_t __pte = *(__ptep); \
  778. if (atomic_read(&(__mm)->mm_users) > 1 || \
  779. (__mm) != current->active_mm) \
  780. ptep_invalidate(__mm, __address, __ptep); \
  781. else \
  782. pte_clear((__mm), (__address), (__ptep)); \
  783. __pte; \
  784. })
  785. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  786. static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
  787. unsigned long address, pte_t *ptep)
  788. {
  789. pte_t pte = *ptep;
  790. ptep_invalidate(vma->vm_mm, address, ptep);
  791. return pte;
  792. }
  793. /*
  794. * The batched pte unmap code uses ptep_get_and_clear_full to clear the
  795. * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
  796. * tlbs of an mm if it can guarantee that the ptes of the mm_struct
  797. * cannot be accessed while the batched unmap is running. In this case
  798. * full==1 and a simple pte_clear is enough. See tlb.h.
  799. */
  800. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  801. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  802. unsigned long addr,
  803. pte_t *ptep, int full)
  804. {
  805. pte_t pte = *ptep;
  806. if (full)
  807. pte_clear(mm, addr, ptep);
  808. else
  809. ptep_invalidate(mm, addr, ptep);
  810. return pte;
  811. }
  812. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  813. #define ptep_set_wrprotect(__mm, __addr, __ptep) \
  814. ({ \
  815. pte_t __pte = *(__ptep); \
  816. if (pte_write(__pte)) { \
  817. if (atomic_read(&(__mm)->mm_users) > 1 || \
  818. (__mm) != current->active_mm) \
  819. ptep_invalidate(__mm, __addr, __ptep); \
  820. set_pte_at(__mm, __addr, __ptep, pte_wrprotect(__pte)); \
  821. } \
  822. })
  823. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  824. #define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
  825. ({ \
  826. int __changed = !pte_same(*(__ptep), __entry); \
  827. if (__changed) { \
  828. ptep_invalidate((__vma)->vm_mm, __addr, __ptep); \
  829. set_pte_at((__vma)->vm_mm, __addr, __ptep, __entry); \
  830. } \
  831. __changed; \
  832. })
  833. /*
  834. * Test and clear dirty bit in storage key.
  835. * We can't clear the changed bit atomically. This is a potential
  836. * race against modification of the referenced bit. This function
  837. * should therefore only be called if it is not mapped in any
  838. * address space.
  839. */
  840. #define __HAVE_ARCH_PAGE_TEST_DIRTY
  841. static inline int page_test_dirty(struct page *page)
  842. {
  843. return (page_get_storage_key(page_to_phys(page)) & _PAGE_CHANGED) != 0;
  844. }
  845. #define __HAVE_ARCH_PAGE_CLEAR_DIRTY
  846. static inline void page_clear_dirty(struct page *page)
  847. {
  848. page_set_storage_key(page_to_phys(page), PAGE_DEFAULT_KEY);
  849. }
  850. /*
  851. * Test and clear referenced bit in storage key.
  852. */
  853. #define __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
  854. static inline int page_test_and_clear_young(struct page *page)
  855. {
  856. unsigned long physpage = page_to_phys(page);
  857. int ccode;
  858. asm volatile(
  859. " rrbe 0,%1\n"
  860. " ipm %0\n"
  861. " srl %0,28\n"
  862. : "=d" (ccode) : "a" (physpage) : "cc" );
  863. return ccode & 2;
  864. }
  865. /*
  866. * Conversion functions: convert a page and protection to a page entry,
  867. * and a page entry and page directory to the page they refer to.
  868. */
  869. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  870. {
  871. pte_t __pte;
  872. pte_val(__pte) = physpage + pgprot_val(pgprot);
  873. return __pte;
  874. }
  875. static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
  876. {
  877. unsigned long physpage = page_to_phys(page);
  878. return mk_pte_phys(physpage, pgprot);
  879. }
  880. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  881. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  882. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  883. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  884. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  885. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  886. #ifndef __s390x__
  887. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  888. #define pud_deref(pmd) ({ BUG(); 0UL; })
  889. #define pgd_deref(pmd) ({ BUG(); 0UL; })
  890. #define pud_offset(pgd, address) ((pud_t *) pgd)
  891. #define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address))
  892. #else /* __s390x__ */
  893. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  894. #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
  895. #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
  896. static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  897. {
  898. pud_t *pud = (pud_t *) pgd;
  899. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  900. pud = (pud_t *) pgd_deref(*pgd);
  901. return pud + pud_index(address);
  902. }
  903. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  904. {
  905. pmd_t *pmd = (pmd_t *) pud;
  906. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  907. pmd = (pmd_t *) pud_deref(*pud);
  908. return pmd + pmd_index(address);
  909. }
  910. #endif /* __s390x__ */
  911. #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))
  912. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  913. #define pte_page(x) pfn_to_page(pte_pfn(x))
  914. #define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
  915. /* Find an entry in the lowest level page table.. */
  916. #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
  917. #define pte_offset_kernel(pmd, address) pte_offset(pmd,address)
  918. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  919. #define pte_offset_map_nested(pmd, address) pte_offset_kernel(pmd, address)
  920. #define pte_unmap(pte) do { } while (0)
  921. #define pte_unmap_nested(pte) do { } while (0)
  922. /*
  923. * 31 bit swap entry format:
  924. * A page-table entry has some bits we have to treat in a special way.
  925. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  926. * exception will occur instead of a page translation exception. The
  927. * specifiation exception has the bad habit not to store necessary
  928. * information in the lowcore.
  929. * Bit 21 and bit 22 are the page invalid bit and the page protection
  930. * bit. We set both to indicate a swapped page.
  931. * Bit 30 and 31 are used to distinguish the different page types. For
  932. * a swapped page these bits need to be zero.
  933. * This leaves the bits 1-19 and bits 24-29 to store type and offset.
  934. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
  935. * plus 24 for the offset.
  936. * 0| offset |0110|o|type |00|
  937. * 0 0000000001111111111 2222 2 22222 33
  938. * 0 1234567890123456789 0123 4 56789 01
  939. *
  940. * 64 bit swap entry format:
  941. * A page-table entry has some bits we have to treat in a special way.
  942. * Bits 52 and bit 55 have to be zero, otherwise an specification
  943. * exception will occur instead of a page translation exception. The
  944. * specifiation exception has the bad habit not to store necessary
  945. * information in the lowcore.
  946. * Bit 53 and bit 54 are the page invalid bit and the page protection
  947. * bit. We set both to indicate a swapped page.
  948. * Bit 62 and 63 are used to distinguish the different page types. For
  949. * a swapped page these bits need to be zero.
  950. * This leaves the bits 0-51 and bits 56-61 to store type and offset.
  951. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51
  952. * plus 56 for the offset.
  953. * | offset |0110|o|type |00|
  954. * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66
  955. * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23
  956. */
  957. #ifndef __s390x__
  958. #define __SWP_OFFSET_MASK (~0UL >> 12)
  959. #else
  960. #define __SWP_OFFSET_MASK (~0UL >> 11)
  961. #endif
  962. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  963. {
  964. pte_t pte;
  965. offset &= __SWP_OFFSET_MASK;
  966. pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) |
  967. ((offset & 1UL) << 7) | ((offset & ~1UL) << 11);
  968. return pte;
  969. }
  970. #define __swp_type(entry) (((entry).val >> 2) & 0x1f)
  971. #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))
  972. #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  973. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  974. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  975. #ifndef __s390x__
  976. # define PTE_FILE_MAX_BITS 26
  977. #else /* __s390x__ */
  978. # define PTE_FILE_MAX_BITS 59
  979. #endif /* __s390x__ */
  980. #define pte_to_pgoff(__pte) \
  981. ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))
  982. #define pgoff_to_pte(__off) \
  983. ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \
  984. | _PAGE_TYPE_FILE })
  985. #endif /* !__ASSEMBLY__ */
  986. #define kern_addr_valid(addr) (1)
  987. extern int vmem_add_mapping(unsigned long start, unsigned long size);
  988. extern int vmem_remove_mapping(unsigned long start, unsigned long size);
  989. extern int s390_enable_sie(void);
  990. /*
  991. * No page table caches to initialise
  992. */
  993. #define pgtable_cache_init() do { } while (0)
  994. #include <asm-generic/pgtable.h>
  995. #endif /* _S390_PAGE_H */