pgtable.h 34 KB

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