pgtable.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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/bug.h>
  33. #include <asm/page.h>
  34. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  35. extern void paging_init(void);
  36. extern void vmem_map_init(void);
  37. extern void fault_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_SWC 0x004 /* SW pte changed bit (for KVM) */
  224. #define _PAGE_SWR 0x008 /* SW pte referenced bit (for KVM) */
  225. #define _PAGE_SPECIAL 0x010 /* SW associated with special page */
  226. #define __HAVE_ARCH_PTE_SPECIAL
  227. /* Set of bits not changed in pte_modify */
  228. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_SWC | _PAGE_SWR)
  229. /* Six different types of pages. */
  230. #define _PAGE_TYPE_EMPTY 0x400
  231. #define _PAGE_TYPE_NONE 0x401
  232. #define _PAGE_TYPE_SWAP 0x403
  233. #define _PAGE_TYPE_FILE 0x601 /* bit 0x002 is used for offset !! */
  234. #define _PAGE_TYPE_RO 0x200
  235. #define _PAGE_TYPE_RW 0x000
  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. *
  264. * pte_none is true for bits combinations 1000, 1010, 1100, 1110
  265. * pte_present is true for bits combinations 0000, 0010, 0100, 0110, 1001
  266. * pte_file is true for bits combinations 1101, 1111
  267. * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
  268. */
  269. #ifndef __s390x__
  270. /* Bits in the segment table address-space-control-element */
  271. #define _ASCE_SPACE_SWITCH 0x80000000UL /* space switch event */
  272. #define _ASCE_ORIGIN_MASK 0x7ffff000UL /* segment table origin */
  273. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  274. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  275. #define _ASCE_TABLE_LENGTH 0x7f /* 128 x 64 entries = 8k */
  276. /* Bits in the segment table entry */
  277. #define _SEGMENT_ENTRY_ORIGIN 0x7fffffc0UL /* page table origin */
  278. #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */
  279. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  280. #define _SEGMENT_ENTRY_COMMON 0x10 /* common segment bit */
  281. #define _SEGMENT_ENTRY_PTL 0x0f /* page table length */
  282. #define _SEGMENT_ENTRY (_SEGMENT_ENTRY_PTL)
  283. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  284. /* Page status table bits for virtualization */
  285. #define RCP_ACC_BITS 0xf0000000UL
  286. #define RCP_FP_BIT 0x08000000UL
  287. #define RCP_PCL_BIT 0x00800000UL
  288. #define RCP_HR_BIT 0x00400000UL
  289. #define RCP_HC_BIT 0x00200000UL
  290. #define RCP_GR_BIT 0x00040000UL
  291. #define RCP_GC_BIT 0x00020000UL
  292. /* User dirty / referenced bit for KVM's migration feature */
  293. #define KVM_UR_BIT 0x00008000UL
  294. #define KVM_UC_BIT 0x00004000UL
  295. #else /* __s390x__ */
  296. /* Bits in the segment/region table address-space-control-element */
  297. #define _ASCE_ORIGIN ~0xfffUL/* segment table origin */
  298. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  299. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  300. #define _ASCE_SPACE_SWITCH 0x40 /* space switch event */
  301. #define _ASCE_REAL_SPACE 0x20 /* real space control */
  302. #define _ASCE_TYPE_MASK 0x0c /* asce table type mask */
  303. #define _ASCE_TYPE_REGION1 0x0c /* region first table type */
  304. #define _ASCE_TYPE_REGION2 0x08 /* region second table type */
  305. #define _ASCE_TYPE_REGION3 0x04 /* region third table type */
  306. #define _ASCE_TYPE_SEGMENT 0x00 /* segment table type */
  307. #define _ASCE_TABLE_LENGTH 0x03 /* region table length */
  308. /* Bits in the region table entry */
  309. #define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */
  310. #define _REGION_ENTRY_INV 0x20 /* invalid region table entry */
  311. #define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */
  312. #define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */
  313. #define _REGION_ENTRY_TYPE_R2 0x08 /* region second table type */
  314. #define _REGION_ENTRY_TYPE_R3 0x04 /* region third table type */
  315. #define _REGION_ENTRY_LENGTH 0x03 /* region third length */
  316. #define _REGION1_ENTRY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_LENGTH)
  317. #define _REGION1_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INV)
  318. #define _REGION2_ENTRY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_LENGTH)
  319. #define _REGION2_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INV)
  320. #define _REGION3_ENTRY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_LENGTH)
  321. #define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INV)
  322. /* Bits in the segment table entry */
  323. #define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL/* segment table origin */
  324. #define _SEGMENT_ENTRY_RO 0x200 /* page protection bit */
  325. #define _SEGMENT_ENTRY_INV 0x20 /* invalid segment table entry */
  326. #define _SEGMENT_ENTRY (0)
  327. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
  328. #define _SEGMENT_ENTRY_LARGE 0x400 /* STE-format control, large page */
  329. #define _SEGMENT_ENTRY_CO 0x100 /* change-recording override */
  330. /* Page status table bits for virtualization */
  331. #define RCP_ACC_BITS 0xf000000000000000UL
  332. #define RCP_FP_BIT 0x0800000000000000UL
  333. #define RCP_PCL_BIT 0x0080000000000000UL
  334. #define RCP_HR_BIT 0x0040000000000000UL
  335. #define RCP_HC_BIT 0x0020000000000000UL
  336. #define RCP_GR_BIT 0x0004000000000000UL
  337. #define RCP_GC_BIT 0x0002000000000000UL
  338. /* User dirty / referenced bit for KVM's migration feature */
  339. #define KVM_UR_BIT 0x0000800000000000UL
  340. #define KVM_UC_BIT 0x0000400000000000UL
  341. #endif /* __s390x__ */
  342. /*
  343. * A user page table pointer has the space-switch-event bit, the
  344. * private-space-control bit and the storage-alteration-event-control
  345. * bit set. A kernel page table pointer doesn't need them.
  346. */
  347. #define _ASCE_USER_BITS (_ASCE_SPACE_SWITCH | _ASCE_PRIVATE_SPACE | \
  348. _ASCE_ALT_EVENT)
  349. /*
  350. * Page protection definitions.
  351. */
  352. #define PAGE_NONE __pgprot(_PAGE_TYPE_NONE)
  353. #define PAGE_RO __pgprot(_PAGE_TYPE_RO)
  354. #define PAGE_RW __pgprot(_PAGE_TYPE_RW)
  355. #define PAGE_KERNEL PAGE_RW
  356. #define PAGE_COPY PAGE_RO
  357. /*
  358. * On s390 the page table entry has an invalid bit and a read-only bit.
  359. * Read permission implies execute permission and write permission
  360. * implies read permission.
  361. */
  362. /*xwr*/
  363. #define __P000 PAGE_NONE
  364. #define __P001 PAGE_RO
  365. #define __P010 PAGE_RO
  366. #define __P011 PAGE_RO
  367. #define __P100 PAGE_RO
  368. #define __P101 PAGE_RO
  369. #define __P110 PAGE_RO
  370. #define __P111 PAGE_RO
  371. #define __S000 PAGE_NONE
  372. #define __S001 PAGE_RO
  373. #define __S010 PAGE_RW
  374. #define __S011 PAGE_RW
  375. #define __S100 PAGE_RO
  376. #define __S101 PAGE_RO
  377. #define __S110 PAGE_RW
  378. #define __S111 PAGE_RW
  379. static inline int mm_exclusive(struct mm_struct *mm)
  380. {
  381. return likely(mm == current->active_mm &&
  382. atomic_read(&mm->context.attach_count) <= 1);
  383. }
  384. static inline int mm_has_pgste(struct mm_struct *mm)
  385. {
  386. #ifdef CONFIG_PGSTE
  387. if (unlikely(mm->context.has_pgste))
  388. return 1;
  389. #endif
  390. return 0;
  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. static inline int pte_same(pte_t a, pte_t b)
  487. {
  488. return pte_val(a) == pte_val(b);
  489. }
  490. static inline pgste_t pgste_get_lock(pte_t *ptep)
  491. {
  492. unsigned long new = 0;
  493. #ifdef CONFIG_PGSTE
  494. unsigned long old;
  495. preempt_disable();
  496. asm(
  497. " lg %0,%2\n"
  498. "0: lgr %1,%0\n"
  499. " nihh %0,0xff7f\n" /* clear RCP_PCL_BIT in old */
  500. " oihh %1,0x0080\n" /* set RCP_PCL_BIT in new */
  501. " csg %0,%1,%2\n"
  502. " jl 0b\n"
  503. : "=&d" (old), "=&d" (new), "=Q" (ptep[PTRS_PER_PTE])
  504. : "Q" (ptep[PTRS_PER_PTE]) : "cc");
  505. #endif
  506. return __pgste(new);
  507. }
  508. static inline void pgste_set_unlock(pte_t *ptep, pgste_t pgste)
  509. {
  510. #ifdef CONFIG_PGSTE
  511. asm(
  512. " nihh %1,0xff7f\n" /* clear RCP_PCL_BIT */
  513. " stg %1,%0\n"
  514. : "=Q" (ptep[PTRS_PER_PTE])
  515. : "d" (pgste_val(pgste)), "Q" (ptep[PTRS_PER_PTE]) : "cc");
  516. preempt_enable();
  517. #endif
  518. }
  519. static inline pgste_t pgste_update_all(pte_t *ptep, pgste_t pgste)
  520. {
  521. #ifdef CONFIG_PGSTE
  522. unsigned long address, bits;
  523. unsigned char skey;
  524. address = pte_val(*ptep) & PAGE_MASK;
  525. skey = page_get_storage_key(address);
  526. bits = skey & (_PAGE_CHANGED | _PAGE_REFERENCED);
  527. /* Clear page changed & referenced bit in the storage key */
  528. if (bits) {
  529. skey ^= bits;
  530. page_set_storage_key(address, skey, 1);
  531. }
  532. /* Transfer page changed & referenced bit to guest bits in pgste */
  533. pgste_val(pgste) |= bits << 48; /* RCP_GR_BIT & RCP_GC_BIT */
  534. /* Get host changed & referenced bits from pgste */
  535. bits |= (pgste_val(pgste) & (RCP_HR_BIT | RCP_HC_BIT)) >> 52;
  536. /* Clear host bits in pgste. */
  537. pgste_val(pgste) &= ~(RCP_HR_BIT | RCP_HC_BIT);
  538. pgste_val(pgste) &= ~(RCP_ACC_BITS | RCP_FP_BIT);
  539. /* Copy page access key and fetch protection bit to pgste */
  540. pgste_val(pgste) |=
  541. (unsigned long) (skey & (_PAGE_ACC_BITS | _PAGE_FP_BIT)) << 56;
  542. /* Transfer changed and referenced to kvm user bits */
  543. pgste_val(pgste) |= bits << 45; /* KVM_UR_BIT & KVM_UC_BIT */
  544. /* Transfer changed & referenced to pte sofware bits */
  545. pte_val(*ptep) |= bits << 1; /* _PAGE_SWR & _PAGE_SWC */
  546. #endif
  547. return pgste;
  548. }
  549. static inline pgste_t pgste_update_young(pte_t *ptep, pgste_t pgste)
  550. {
  551. #ifdef CONFIG_PGSTE
  552. int young;
  553. young = page_reset_referenced(pte_val(*ptep) & PAGE_MASK);
  554. /* Transfer page referenced bit to pte software bit (host view) */
  555. if (young || (pgste_val(pgste) & RCP_HR_BIT))
  556. pte_val(*ptep) |= _PAGE_SWR;
  557. /* Clear host referenced bit in pgste. */
  558. pgste_val(pgste) &= ~RCP_HR_BIT;
  559. /* Transfer page referenced bit to guest bit in pgste */
  560. pgste_val(pgste) |= (unsigned long) young << 50; /* set RCP_GR_BIT */
  561. #endif
  562. return pgste;
  563. }
  564. static inline void pgste_set_pte(pte_t *ptep, pgste_t pgste)
  565. {
  566. #ifdef CONFIG_PGSTE
  567. unsigned long address;
  568. unsigned long okey, nkey;
  569. address = pte_val(*ptep) & PAGE_MASK;
  570. okey = nkey = page_get_storage_key(address);
  571. nkey &= ~(_PAGE_ACC_BITS | _PAGE_FP_BIT);
  572. /* Set page access key and fetch protection bit from pgste */
  573. nkey |= (pgste_val(pgste) & (RCP_ACC_BITS | RCP_FP_BIT)) >> 56;
  574. if (okey != nkey)
  575. page_set_storage_key(address, nkey, 1);
  576. #endif
  577. }
  578. /**
  579. * struct gmap_struct - guest address space
  580. * @mm: pointer to the parent mm_struct
  581. * @table: pointer to the page directory
  582. * @asce: address space control element for gmap page table
  583. * @crst_list: list of all crst tables used in the guest address space
  584. */
  585. struct gmap {
  586. struct list_head list;
  587. struct mm_struct *mm;
  588. unsigned long *table;
  589. unsigned long asce;
  590. struct list_head crst_list;
  591. };
  592. /**
  593. * struct gmap_rmap - reverse mapping for segment table entries
  594. * @next: pointer to the next gmap_rmap structure in the list
  595. * @entry: pointer to a segment table entry
  596. */
  597. struct gmap_rmap {
  598. struct list_head list;
  599. unsigned long *entry;
  600. };
  601. /**
  602. * struct gmap_pgtable - gmap information attached to a page table
  603. * @vmaddr: address of the 1MB segment in the process virtual memory
  604. * @mapper: list of segment table entries maping a page table
  605. */
  606. struct gmap_pgtable {
  607. unsigned long vmaddr;
  608. struct list_head mapper;
  609. };
  610. struct gmap *gmap_alloc(struct mm_struct *mm);
  611. void gmap_free(struct gmap *gmap);
  612. void gmap_enable(struct gmap *gmap);
  613. void gmap_disable(struct gmap *gmap);
  614. int gmap_map_segment(struct gmap *gmap, unsigned long from,
  615. unsigned long to, unsigned long length);
  616. int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
  617. unsigned long __gmap_fault(unsigned long address, struct gmap *);
  618. unsigned long gmap_fault(unsigned long address, struct gmap *);
  619. void gmap_discard(unsigned long from, unsigned long to, struct gmap *);
  620. /*
  621. * Certain architectures need to do special things when PTEs
  622. * within a page table are directly modified. Thus, the following
  623. * hook is made available.
  624. */
  625. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  626. pte_t *ptep, pte_t entry)
  627. {
  628. pgste_t pgste;
  629. if (mm_has_pgste(mm)) {
  630. pgste = pgste_get_lock(ptep);
  631. pgste_set_pte(ptep, pgste);
  632. *ptep = entry;
  633. pgste_set_unlock(ptep, pgste);
  634. } else
  635. *ptep = entry;
  636. }
  637. /*
  638. * query functions pte_write/pte_dirty/pte_young only work if
  639. * pte_present() is true. Undefined behaviour if not..
  640. */
  641. static inline int pte_write(pte_t pte)
  642. {
  643. return (pte_val(pte) & _PAGE_RO) == 0;
  644. }
  645. static inline int pte_dirty(pte_t pte)
  646. {
  647. #ifdef CONFIG_PGSTE
  648. if (pte_val(pte) & _PAGE_SWC)
  649. return 1;
  650. #endif
  651. return 0;
  652. }
  653. static inline int pte_young(pte_t pte)
  654. {
  655. #ifdef CONFIG_PGSTE
  656. if (pte_val(pte) & _PAGE_SWR)
  657. return 1;
  658. #endif
  659. return 0;
  660. }
  661. /*
  662. * pgd/pmd/pte modification functions
  663. */
  664. static inline void pgd_clear(pgd_t *pgd)
  665. {
  666. #ifdef __s390x__
  667. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  668. pgd_val(*pgd) = _REGION2_ENTRY_EMPTY;
  669. #endif
  670. }
  671. static inline void pud_clear(pud_t *pud)
  672. {
  673. #ifdef __s390x__
  674. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  675. pud_val(*pud) = _REGION3_ENTRY_EMPTY;
  676. #endif
  677. }
  678. static inline void pmd_clear(pmd_t *pmdp)
  679. {
  680. pmd_val(*pmdp) = _SEGMENT_ENTRY_EMPTY;
  681. }
  682. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  683. {
  684. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  685. }
  686. /*
  687. * The following pte modification functions only work if
  688. * pte_present() is true. Undefined behaviour if not..
  689. */
  690. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  691. {
  692. pte_val(pte) &= _PAGE_CHG_MASK;
  693. pte_val(pte) |= pgprot_val(newprot);
  694. return pte;
  695. }
  696. static inline pte_t pte_wrprotect(pte_t pte)
  697. {
  698. /* Do not clobber _PAGE_TYPE_NONE pages! */
  699. if (!(pte_val(pte) & _PAGE_INVALID))
  700. pte_val(pte) |= _PAGE_RO;
  701. return pte;
  702. }
  703. static inline pte_t pte_mkwrite(pte_t pte)
  704. {
  705. pte_val(pte) &= ~_PAGE_RO;
  706. return pte;
  707. }
  708. static inline pte_t pte_mkclean(pte_t pte)
  709. {
  710. #ifdef CONFIG_PGSTE
  711. pte_val(pte) &= ~_PAGE_SWC;
  712. #endif
  713. return pte;
  714. }
  715. static inline pte_t pte_mkdirty(pte_t pte)
  716. {
  717. return pte;
  718. }
  719. static inline pte_t pte_mkold(pte_t pte)
  720. {
  721. #ifdef CONFIG_PGSTE
  722. pte_val(pte) &= ~_PAGE_SWR;
  723. #endif
  724. return pte;
  725. }
  726. static inline pte_t pte_mkyoung(pte_t pte)
  727. {
  728. return pte;
  729. }
  730. static inline pte_t pte_mkspecial(pte_t pte)
  731. {
  732. pte_val(pte) |= _PAGE_SPECIAL;
  733. return pte;
  734. }
  735. #ifdef CONFIG_HUGETLB_PAGE
  736. static inline pte_t pte_mkhuge(pte_t pte)
  737. {
  738. /*
  739. * PROT_NONE needs to be remapped from the pte type to the ste type.
  740. * The HW invalid bit is also different for pte and ste. The pte
  741. * invalid bit happens to be the same as the ste _SEGMENT_ENTRY_LARGE
  742. * bit, so we don't have to clear it.
  743. */
  744. if (pte_val(pte) & _PAGE_INVALID) {
  745. if (pte_val(pte) & _PAGE_SWT)
  746. pte_val(pte) |= _HPAGE_TYPE_NONE;
  747. pte_val(pte) |= _SEGMENT_ENTRY_INV;
  748. }
  749. /*
  750. * Clear SW pte bits SWT and SWX, there are no SW bits in a segment
  751. * table entry.
  752. */
  753. pte_val(pte) &= ~(_PAGE_SWT | _PAGE_SWX);
  754. /*
  755. * Also set the change-override bit because we don't need dirty bit
  756. * tracking for hugetlbfs pages.
  757. */
  758. pte_val(pte) |= (_SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_CO);
  759. return pte;
  760. }
  761. #endif
  762. /*
  763. * Get (and clear) the user dirty bit for a pte.
  764. */
  765. static inline int ptep_test_and_clear_user_dirty(struct mm_struct *mm,
  766. pte_t *ptep)
  767. {
  768. pgste_t pgste;
  769. int dirty = 0;
  770. if (mm_has_pgste(mm)) {
  771. pgste = pgste_get_lock(ptep);
  772. pgste = pgste_update_all(ptep, pgste);
  773. dirty = !!(pgste_val(pgste) & KVM_UC_BIT);
  774. pgste_val(pgste) &= ~KVM_UC_BIT;
  775. pgste_set_unlock(ptep, pgste);
  776. return dirty;
  777. }
  778. return dirty;
  779. }
  780. /*
  781. * Get (and clear) the user referenced bit for a pte.
  782. */
  783. static inline int ptep_test_and_clear_user_young(struct mm_struct *mm,
  784. pte_t *ptep)
  785. {
  786. pgste_t pgste;
  787. int young = 0;
  788. if (mm_has_pgste(mm)) {
  789. pgste = pgste_get_lock(ptep);
  790. pgste = pgste_update_young(ptep, pgste);
  791. young = !!(pgste_val(pgste) & KVM_UR_BIT);
  792. pgste_val(pgste) &= ~KVM_UR_BIT;
  793. pgste_set_unlock(ptep, pgste);
  794. }
  795. return young;
  796. }
  797. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  798. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  799. unsigned long addr, pte_t *ptep)
  800. {
  801. pgste_t pgste;
  802. pte_t pte;
  803. if (mm_has_pgste(vma->vm_mm)) {
  804. pgste = pgste_get_lock(ptep);
  805. pgste = pgste_update_young(ptep, pgste);
  806. pte = *ptep;
  807. *ptep = pte_mkold(pte);
  808. pgste_set_unlock(ptep, pgste);
  809. return pte_young(pte);
  810. }
  811. return 0;
  812. }
  813. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  814. static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  815. unsigned long address, pte_t *ptep)
  816. {
  817. /* No need to flush TLB
  818. * On s390 reference bits are in storage key and never in TLB
  819. * With virtualization we handle the reference bit, without we
  820. * we can simply return */
  821. return ptep_test_and_clear_young(vma, address, ptep);
  822. }
  823. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  824. {
  825. if (!(pte_val(*ptep) & _PAGE_INVALID)) {
  826. #ifndef __s390x__
  827. /* pto must point to the start of the segment table */
  828. pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
  829. #else
  830. /* ipte in zarch mode can do the math */
  831. pte_t *pto = ptep;
  832. #endif
  833. asm volatile(
  834. " ipte %2,%3"
  835. : "=m" (*ptep) : "m" (*ptep),
  836. "a" (pto), "a" (address));
  837. }
  838. }
  839. /*
  840. * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
  841. * both clear the TLB for the unmapped pte. The reason is that
  842. * ptep_get_and_clear is used in common code (e.g. change_pte_range)
  843. * to modify an active pte. The sequence is
  844. * 1) ptep_get_and_clear
  845. * 2) set_pte_at
  846. * 3) flush_tlb_range
  847. * On s390 the tlb needs to get flushed with the modification of the pte
  848. * if the pte is active. The only way how this can be implemented is to
  849. * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range
  850. * is a nop.
  851. */
  852. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  853. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  854. unsigned long address, pte_t *ptep)
  855. {
  856. pgste_t pgste;
  857. pte_t pte;
  858. mm->context.flush_mm = 1;
  859. if (mm_has_pgste(mm))
  860. pgste = pgste_get_lock(ptep);
  861. pte = *ptep;
  862. if (!mm_exclusive(mm))
  863. __ptep_ipte(address, ptep);
  864. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  865. if (mm_has_pgste(mm)) {
  866. pgste = pgste_update_all(&pte, pgste);
  867. pgste_set_unlock(ptep, pgste);
  868. }
  869. return pte;
  870. }
  871. #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
  872. static inline pte_t ptep_modify_prot_start(struct mm_struct *mm,
  873. unsigned long address,
  874. pte_t *ptep)
  875. {
  876. pte_t pte;
  877. mm->context.flush_mm = 1;
  878. if (mm_has_pgste(mm))
  879. pgste_get_lock(ptep);
  880. pte = *ptep;
  881. if (!mm_exclusive(mm))
  882. __ptep_ipte(address, ptep);
  883. return pte;
  884. }
  885. static inline void ptep_modify_prot_commit(struct mm_struct *mm,
  886. unsigned long address,
  887. pte_t *ptep, pte_t pte)
  888. {
  889. *ptep = pte;
  890. if (mm_has_pgste(mm))
  891. pgste_set_unlock(ptep, *(pgste_t *)(ptep + PTRS_PER_PTE));
  892. }
  893. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  894. static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
  895. unsigned long address, pte_t *ptep)
  896. {
  897. pgste_t pgste;
  898. pte_t pte;
  899. if (mm_has_pgste(vma->vm_mm))
  900. pgste = pgste_get_lock(ptep);
  901. pte = *ptep;
  902. __ptep_ipte(address, ptep);
  903. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  904. if (mm_has_pgste(vma->vm_mm)) {
  905. pgste = pgste_update_all(&pte, pgste);
  906. pgste_set_unlock(ptep, pgste);
  907. }
  908. return pte;
  909. }
  910. /*
  911. * The batched pte unmap code uses ptep_get_and_clear_full to clear the
  912. * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
  913. * tlbs of an mm if it can guarantee that the ptes of the mm_struct
  914. * cannot be accessed while the batched unmap is running. In this case
  915. * full==1 and a simple pte_clear is enough. See tlb.h.
  916. */
  917. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  918. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  919. unsigned long address,
  920. pte_t *ptep, int full)
  921. {
  922. pgste_t pgste;
  923. pte_t pte;
  924. if (mm_has_pgste(mm))
  925. pgste = pgste_get_lock(ptep);
  926. pte = *ptep;
  927. if (!full)
  928. __ptep_ipte(address, ptep);
  929. pte_val(*ptep) = _PAGE_TYPE_EMPTY;
  930. if (mm_has_pgste(mm)) {
  931. pgste = pgste_update_all(&pte, pgste);
  932. pgste_set_unlock(ptep, pgste);
  933. }
  934. return pte;
  935. }
  936. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  937. static inline pte_t ptep_set_wrprotect(struct mm_struct *mm,
  938. unsigned long address, pte_t *ptep)
  939. {
  940. pgste_t pgste;
  941. pte_t pte = *ptep;
  942. if (pte_write(pte)) {
  943. mm->context.flush_mm = 1;
  944. if (mm_has_pgste(mm))
  945. pgste = pgste_get_lock(ptep);
  946. if (!mm_exclusive(mm))
  947. __ptep_ipte(address, ptep);
  948. *ptep = pte_wrprotect(pte);
  949. if (mm_has_pgste(mm))
  950. pgste_set_unlock(ptep, pgste);
  951. }
  952. return pte;
  953. }
  954. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  955. static inline int ptep_set_access_flags(struct vm_area_struct *vma,
  956. unsigned long address, pte_t *ptep,
  957. pte_t entry, int dirty)
  958. {
  959. pgste_t pgste;
  960. if (pte_same(*ptep, entry))
  961. return 0;
  962. if (mm_has_pgste(vma->vm_mm))
  963. pgste = pgste_get_lock(ptep);
  964. __ptep_ipte(address, ptep);
  965. *ptep = entry;
  966. if (mm_has_pgste(vma->vm_mm))
  967. pgste_set_unlock(ptep, pgste);
  968. return 1;
  969. }
  970. /*
  971. * Conversion functions: convert a page and protection to a page entry,
  972. * and a page entry and page directory to the page they refer to.
  973. */
  974. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  975. {
  976. pte_t __pte;
  977. pte_val(__pte) = physpage + pgprot_val(pgprot);
  978. return __pte;
  979. }
  980. static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
  981. {
  982. unsigned long physpage = page_to_phys(page);
  983. return mk_pte_phys(physpage, pgprot);
  984. }
  985. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  986. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  987. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  988. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  989. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  990. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  991. #ifndef __s390x__
  992. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  993. #define pud_deref(pmd) ({ BUG(); 0UL; })
  994. #define pgd_deref(pmd) ({ BUG(); 0UL; })
  995. #define pud_offset(pgd, address) ((pud_t *) pgd)
  996. #define pmd_offset(pud, address) ((pmd_t *) pud + pmd_index(address))
  997. #else /* __s390x__ */
  998. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  999. #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
  1000. #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
  1001. static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  1002. {
  1003. pud_t *pud = (pud_t *) pgd;
  1004. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  1005. pud = (pud_t *) pgd_deref(*pgd);
  1006. return pud + pud_index(address);
  1007. }
  1008. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  1009. {
  1010. pmd_t *pmd = (pmd_t *) pud;
  1011. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  1012. pmd = (pmd_t *) pud_deref(*pud);
  1013. return pmd + pmd_index(address);
  1014. }
  1015. #endif /* __s390x__ */
  1016. #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))
  1017. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  1018. #define pte_page(x) pfn_to_page(pte_pfn(x))
  1019. #define pmd_page(pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
  1020. /* Find an entry in the lowest level page table.. */
  1021. #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
  1022. #define pte_offset_kernel(pmd, address) pte_offset(pmd,address)
  1023. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  1024. #define pte_unmap(pte) do { } while (0)
  1025. /*
  1026. * 31 bit swap entry format:
  1027. * A page-table entry has some bits we have to treat in a special way.
  1028. * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  1029. * exception will occur instead of a page translation exception. The
  1030. * specifiation exception has the bad habit not to store necessary
  1031. * information in the lowcore.
  1032. * Bit 21 and bit 22 are the page invalid bit and the page protection
  1033. * bit. We set both to indicate a swapped page.
  1034. * Bit 30 and 31 are used to distinguish the different page types. For
  1035. * a swapped page these bits need to be zero.
  1036. * This leaves the bits 1-19 and bits 24-29 to store type and offset.
  1037. * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
  1038. * plus 24 for the offset.
  1039. * 0| offset |0110|o|type |00|
  1040. * 0 0000000001111111111 2222 2 22222 33
  1041. * 0 1234567890123456789 0123 4 56789 01
  1042. *
  1043. * 64 bit swap entry format:
  1044. * A page-table entry has some bits we have to treat in a special way.
  1045. * Bits 52 and bit 55 have to be zero, otherwise an specification
  1046. * exception will occur instead of a page translation exception. The
  1047. * specifiation exception has the bad habit not to store necessary
  1048. * information in the lowcore.
  1049. * Bit 53 and bit 54 are the page invalid bit and the page protection
  1050. * bit. We set both to indicate a swapped page.
  1051. * Bit 62 and 63 are used to distinguish the different page types. For
  1052. * a swapped page these bits need to be zero.
  1053. * This leaves the bits 0-51 and bits 56-61 to store type and offset.
  1054. * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51
  1055. * plus 56 for the offset.
  1056. * | offset |0110|o|type |00|
  1057. * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66
  1058. * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23
  1059. */
  1060. #ifndef __s390x__
  1061. #define __SWP_OFFSET_MASK (~0UL >> 12)
  1062. #else
  1063. #define __SWP_OFFSET_MASK (~0UL >> 11)
  1064. #endif
  1065. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  1066. {
  1067. pte_t pte;
  1068. offset &= __SWP_OFFSET_MASK;
  1069. pte_val(pte) = _PAGE_TYPE_SWAP | ((type & 0x1f) << 2) |
  1070. ((offset & 1UL) << 7) | ((offset & ~1UL) << 11);
  1071. return pte;
  1072. }
  1073. #define __swp_type(entry) (((entry).val >> 2) & 0x1f)
  1074. #define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1))
  1075. #define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  1076. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  1077. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  1078. #ifndef __s390x__
  1079. # define PTE_FILE_MAX_BITS 26
  1080. #else /* __s390x__ */
  1081. # define PTE_FILE_MAX_BITS 59
  1082. #endif /* __s390x__ */
  1083. #define pte_to_pgoff(__pte) \
  1084. ((((__pte).pte >> 12) << 7) + (((__pte).pte >> 1) & 0x7f))
  1085. #define pgoff_to_pte(__off) \
  1086. ((pte_t) { ((((__off) & 0x7f) << 1) + (((__off) >> 7) << 12)) \
  1087. | _PAGE_TYPE_FILE })
  1088. #endif /* !__ASSEMBLY__ */
  1089. #define kern_addr_valid(addr) (1)
  1090. extern int vmem_add_mapping(unsigned long start, unsigned long size);
  1091. extern int vmem_remove_mapping(unsigned long start, unsigned long size);
  1092. extern int s390_enable_sie(void);
  1093. /*
  1094. * No page table caches to initialise
  1095. */
  1096. #define pgtable_cache_init() do { } while (0)
  1097. #include <asm-generic/pgtable.h>
  1098. #endif /* _S390_PAGE_H */