pgtable.h 35 KB

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