pgtable.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999, 2000
  4. * Author(s): Hartmut Penner (hp@de.ibm.com)
  5. * Ulrich Weigand (weigand@de.ibm.com)
  6. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. *
  8. * Derived from "include/asm-i386/pgtable.h"
  9. */
  10. #ifndef _ASM_S390_PGTABLE_H
  11. #define _ASM_S390_PGTABLE_H
  12. /*
  13. * The Linux memory management assumes a three-level page table setup.
  14. * For s390 64 bit we use up to four of the five levels the hardware
  15. * provides (region first tables are not used).
  16. *
  17. * The "pgd_xxx()" functions are trivial for a folded two-level
  18. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  19. * into the pgd entry)
  20. *
  21. * This file contains the functions and defines necessary to modify and use
  22. * the S390 page table tree.
  23. */
  24. #ifndef __ASSEMBLY__
  25. #include <linux/sched.h>
  26. #include <linux/mm_types.h>
  27. #include <linux/page-flags.h>
  28. #include <linux/radix-tree.h>
  29. #include <asm/bug.h>
  30. #include <asm/page.h>
  31. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  32. extern void paging_init(void);
  33. extern void vmem_map_init(void);
  34. /*
  35. * The S390 doesn't have any external MMU info: the kernel page
  36. * tables contain all the necessary information.
  37. */
  38. #define update_mmu_cache(vma, address, ptep) do { } while (0)
  39. #define update_mmu_cache_pmd(vma, address, ptep) do { } while (0)
  40. /*
  41. * ZERO_PAGE is a global shared page that is always zero; used
  42. * for zero-mapped memory areas etc..
  43. */
  44. extern unsigned long empty_zero_page;
  45. extern unsigned long zero_page_mask;
  46. #define ZERO_PAGE(vaddr) \
  47. (virt_to_page((void *)(empty_zero_page + \
  48. (((unsigned long)(vaddr)) &zero_page_mask))))
  49. #define __HAVE_COLOR_ZERO_PAGE
  50. /* TODO: s390 cannot support io_remap_pfn_range... */
  51. #endif /* !__ASSEMBLY__ */
  52. /*
  53. * PMD_SHIFT determines the size of the area a second-level page
  54. * table can map
  55. * PGDIR_SHIFT determines what a third-level page table entry can map
  56. */
  57. #define PMD_SHIFT 20
  58. #define PUD_SHIFT 31
  59. #define PGDIR_SHIFT 42
  60. #define PMD_SIZE (1UL << PMD_SHIFT)
  61. #define PMD_MASK (~(PMD_SIZE-1))
  62. #define PUD_SIZE (1UL << PUD_SHIFT)
  63. #define PUD_MASK (~(PUD_SIZE-1))
  64. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  65. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  66. /*
  67. * entries per page directory level: the S390 is two-level, so
  68. * we don't really have any PMD directory physically.
  69. * for S390 segment-table entries are combined to one PGD
  70. * that leads to 1024 pte per pgd
  71. */
  72. #define PTRS_PER_PTE 256
  73. #define PTRS_PER_PMD 2048
  74. #define PTRS_PER_PUD 2048
  75. #define PTRS_PER_PGD 2048
  76. #define FIRST_USER_ADDRESS 0UL
  77. #define pte_ERROR(e) \
  78. printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e))
  79. #define pmd_ERROR(e) \
  80. printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e))
  81. #define pud_ERROR(e) \
  82. printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e))
  83. #define pgd_ERROR(e) \
  84. printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e))
  85. #ifndef __ASSEMBLY__
  86. /*
  87. * The vmalloc and module area will always be on the topmost area of the
  88. * kernel mapping. We reserve 128GB (64bit) for vmalloc and modules.
  89. * On 64 bit kernels we have a 2GB area at the top of the vmalloc area where
  90. * modules will reside. That makes sure that inter module branches always
  91. * happen without trampolines and in addition the placement within a 2GB frame
  92. * is branch prediction unit friendly.
  93. */
  94. extern unsigned long VMALLOC_START;
  95. extern unsigned long VMALLOC_END;
  96. extern struct page *vmemmap;
  97. #define VMEM_MAX_PHYS ((unsigned long) vmemmap)
  98. extern unsigned long MODULES_VADDR;
  99. extern unsigned long MODULES_END;
  100. #define MODULES_VADDR MODULES_VADDR
  101. #define MODULES_END MODULES_END
  102. #define MODULES_LEN (1UL << 31)
  103. static inline int is_module_addr(void *addr)
  104. {
  105. BUILD_BUG_ON(MODULES_LEN > (1UL << 31));
  106. if (addr < (void *)MODULES_VADDR)
  107. return 0;
  108. if (addr > (void *)MODULES_END)
  109. return 0;
  110. return 1;
  111. }
  112. /*
  113. * A 64 bit pagetable entry of S390 has following format:
  114. * | PFRA |0IPC| OS |
  115. * 0000000000111111111122222222223333333333444444444455555555556666
  116. * 0123456789012345678901234567890123456789012345678901234567890123
  117. *
  118. * I Page-Invalid Bit: Page is not available for address-translation
  119. * P Page-Protection Bit: Store access not possible for page
  120. * C Change-bit override: HW is not required to set change bit
  121. *
  122. * A 64 bit segmenttable entry of S390 has following format:
  123. * | P-table origin | TT
  124. * 0000000000111111111122222222223333333333444444444455555555556666
  125. * 0123456789012345678901234567890123456789012345678901234567890123
  126. *
  127. * I Segment-Invalid Bit: Segment is not available for address-translation
  128. * C Common-Segment Bit: Segment is not private (PoP 3-30)
  129. * P Page-Protection Bit: Store access not possible for page
  130. * TT Type 00
  131. *
  132. * A 64 bit region table entry of S390 has following format:
  133. * | S-table origin | TF TTTL
  134. * 0000000000111111111122222222223333333333444444444455555555556666
  135. * 0123456789012345678901234567890123456789012345678901234567890123
  136. *
  137. * I Segment-Invalid Bit: Segment is not available for address-translation
  138. * TT Type 01
  139. * TF
  140. * TL Table length
  141. *
  142. * The 64 bit regiontable origin of S390 has following format:
  143. * | region table origon | DTTL
  144. * 0000000000111111111122222222223333333333444444444455555555556666
  145. * 0123456789012345678901234567890123456789012345678901234567890123
  146. *
  147. * X Space-Switch event:
  148. * G Segment-Invalid Bit:
  149. * P Private-Space Bit:
  150. * S Storage-Alteration:
  151. * R Real space
  152. * TL Table-Length:
  153. *
  154. * A storage key has the following format:
  155. * | ACC |F|R|C|0|
  156. * 0 3 4 5 6 7
  157. * ACC: access key
  158. * F : fetch protection bit
  159. * R : referenced bit
  160. * C : changed bit
  161. */
  162. /* Hardware bits in the page table entry */
  163. #define _PAGE_PROTECT 0x200 /* HW read-only bit */
  164. #define _PAGE_INVALID 0x400 /* HW invalid bit */
  165. #define _PAGE_LARGE 0x800 /* Bit to mark a large pte */
  166. /* Software bits in the page table entry */
  167. #define _PAGE_PRESENT 0x001 /* SW pte present bit */
  168. #define _PAGE_YOUNG 0x004 /* SW pte young bit */
  169. #define _PAGE_DIRTY 0x008 /* SW pte dirty bit */
  170. #define _PAGE_READ 0x010 /* SW pte read bit */
  171. #define _PAGE_WRITE 0x020 /* SW pte write bit */
  172. #define _PAGE_SPECIAL 0x040 /* SW associated with special page */
  173. #define _PAGE_UNUSED 0x080 /* SW bit for pgste usage state */
  174. #define __HAVE_ARCH_PTE_SPECIAL
  175. /* Set of bits not changed in pte_modify */
  176. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \
  177. _PAGE_YOUNG)
  178. /*
  179. * handle_pte_fault uses pte_present and pte_none to find out the pte type
  180. * WITHOUT holding the page table lock. The _PAGE_PRESENT bit is used to
  181. * distinguish present from not-present ptes. It is changed only with the page
  182. * table lock held.
  183. *
  184. * The following table gives the different possible bit combinations for
  185. * the pte hardware and software bits in the last 12 bits of a pte
  186. * (. unassigned bit, x don't care, t swap type):
  187. *
  188. * 842100000000
  189. * 000084210000
  190. * 000000008421
  191. * .IR.uswrdy.p
  192. * empty .10.00000000
  193. * swap .11..ttttt.0
  194. * prot-none, clean, old .11.xx0000.1
  195. * prot-none, clean, young .11.xx0001.1
  196. * prot-none, dirty, old .10.xx0010.1
  197. * prot-none, dirty, young .10.xx0011.1
  198. * read-only, clean, old .11.xx0100.1
  199. * read-only, clean, young .01.xx0101.1
  200. * read-only, dirty, old .11.xx0110.1
  201. * read-only, dirty, young .01.xx0111.1
  202. * read-write, clean, old .11.xx1100.1
  203. * read-write, clean, young .01.xx1101.1
  204. * read-write, dirty, old .10.xx1110.1
  205. * read-write, dirty, young .00.xx1111.1
  206. * HW-bits: R read-only, I invalid
  207. * SW-bits: p present, y young, d dirty, r read, w write, s special,
  208. * u unused, l large
  209. *
  210. * pte_none is true for the bit pattern .10.00000000, pte == 0x400
  211. * pte_swap is true for the bit pattern .11..ooooo.0, (pte & 0x201) == 0x200
  212. * pte_present is true for the bit pattern .xx.xxxxxx.1, (pte & 0x001) == 0x001
  213. */
  214. /* Bits in the segment/region table address-space-control-element */
  215. #define _ASCE_ORIGIN ~0xfffUL/* segment table origin */
  216. #define _ASCE_PRIVATE_SPACE 0x100 /* private space control */
  217. #define _ASCE_ALT_EVENT 0x80 /* storage alteration event control */
  218. #define _ASCE_SPACE_SWITCH 0x40 /* space switch event */
  219. #define _ASCE_REAL_SPACE 0x20 /* real space control */
  220. #define _ASCE_TYPE_MASK 0x0c /* asce table type mask */
  221. #define _ASCE_TYPE_REGION1 0x0c /* region first table type */
  222. #define _ASCE_TYPE_REGION2 0x08 /* region second table type */
  223. #define _ASCE_TYPE_REGION3 0x04 /* region third table type */
  224. #define _ASCE_TYPE_SEGMENT 0x00 /* segment table type */
  225. #define _ASCE_TABLE_LENGTH 0x03 /* region table length */
  226. /* Bits in the region table entry */
  227. #define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */
  228. #define _REGION_ENTRY_PROTECT 0x200 /* region protection bit */
  229. #define _REGION_ENTRY_INVALID 0x20 /* invalid region table entry */
  230. #define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */
  231. #define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */
  232. #define _REGION_ENTRY_TYPE_R2 0x08 /* region second table type */
  233. #define _REGION_ENTRY_TYPE_R3 0x04 /* region third table type */
  234. #define _REGION_ENTRY_LENGTH 0x03 /* region third length */
  235. #define _REGION1_ENTRY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_LENGTH)
  236. #define _REGION1_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INVALID)
  237. #define _REGION2_ENTRY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_LENGTH)
  238. #define _REGION2_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INVALID)
  239. #define _REGION3_ENTRY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_LENGTH)
  240. #define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INVALID)
  241. #define _REGION3_ENTRY_LARGE 0x400 /* RTTE-format control, large page */
  242. #define _REGION3_ENTRY_RO 0x200 /* page protection bit */
  243. /* Bits in the segment table entry */
  244. #define _SEGMENT_ENTRY_BITS 0xfffffffffffffe33UL
  245. #define _SEGMENT_ENTRY_BITS_LARGE 0xfffffffffff0ff33UL
  246. #define _SEGMENT_ENTRY_ORIGIN_LARGE ~0xfffffUL /* large page address */
  247. #define _SEGMENT_ENTRY_ORIGIN ~0x7ffUL/* segment table origin */
  248. #define _SEGMENT_ENTRY_PROTECT 0x200 /* page protection bit */
  249. #define _SEGMENT_ENTRY_INVALID 0x20 /* invalid segment table entry */
  250. #define _SEGMENT_ENTRY (0)
  251. #define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INVALID)
  252. #define _SEGMENT_ENTRY_DIRTY 0x2000 /* SW segment dirty bit */
  253. #define _SEGMENT_ENTRY_YOUNG 0x1000 /* SW segment young bit */
  254. #define _SEGMENT_ENTRY_SPLIT 0x0800 /* THP splitting bit */
  255. #define _SEGMENT_ENTRY_LARGE 0x0400 /* STE-format control, large page */
  256. #define _SEGMENT_ENTRY_READ 0x0002 /* SW segment read bit */
  257. #define _SEGMENT_ENTRY_WRITE 0x0001 /* SW segment write bit */
  258. /*
  259. * Segment table entry encoding (R = read-only, I = invalid, y = young bit):
  260. * dy..R...I...wr
  261. * prot-none, clean, old 00..1...1...00
  262. * prot-none, clean, young 01..1...1...00
  263. * prot-none, dirty, old 10..1...1...00
  264. * prot-none, dirty, young 11..1...1...00
  265. * read-only, clean, old 00..1...1...01
  266. * read-only, clean, young 01..1...0...01
  267. * read-only, dirty, old 10..1...1...01
  268. * read-only, dirty, young 11..1...0...01
  269. * read-write, clean, old 00..1...1...11
  270. * read-write, clean, young 01..1...0...11
  271. * read-write, dirty, old 10..0...1...11
  272. * read-write, dirty, young 11..0...0...11
  273. * The segment table origin is used to distinguish empty (origin==0) from
  274. * read-write, old segment table entries (origin!=0)
  275. * HW-bits: R read-only, I invalid
  276. * SW-bits: y young, d dirty, r read, w write
  277. */
  278. #define _SEGMENT_ENTRY_SPLIT_BIT 11 /* THP splitting bit number */
  279. /* Page status table bits for virtualization */
  280. #define PGSTE_ACC_BITS 0xf000000000000000UL
  281. #define PGSTE_FP_BIT 0x0800000000000000UL
  282. #define PGSTE_PCL_BIT 0x0080000000000000UL
  283. #define PGSTE_HR_BIT 0x0040000000000000UL
  284. #define PGSTE_HC_BIT 0x0020000000000000UL
  285. #define PGSTE_GR_BIT 0x0004000000000000UL
  286. #define PGSTE_GC_BIT 0x0002000000000000UL
  287. #define PGSTE_UC_BIT 0x0000800000000000UL /* user dirty (migration) */
  288. #define PGSTE_IN_BIT 0x0000400000000000UL /* IPTE notify bit */
  289. /* Guest Page State used for virtualization */
  290. #define _PGSTE_GPS_ZERO 0x0000000080000000UL
  291. #define _PGSTE_GPS_USAGE_MASK 0x0000000003000000UL
  292. #define _PGSTE_GPS_USAGE_STABLE 0x0000000000000000UL
  293. #define _PGSTE_GPS_USAGE_UNUSED 0x0000000001000000UL
  294. /*
  295. * A user page table pointer has the space-switch-event bit, the
  296. * private-space-control bit and the storage-alteration-event-control
  297. * bit set. A kernel page table pointer doesn't need them.
  298. */
  299. #define _ASCE_USER_BITS (_ASCE_SPACE_SWITCH | _ASCE_PRIVATE_SPACE | \
  300. _ASCE_ALT_EVENT)
  301. /*
  302. * Page protection definitions.
  303. */
  304. #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_INVALID)
  305. #define PAGE_READ __pgprot(_PAGE_PRESENT | _PAGE_READ | \
  306. _PAGE_INVALID | _PAGE_PROTECT)
  307. #define PAGE_WRITE __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  308. _PAGE_INVALID | _PAGE_PROTECT)
  309. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  310. _PAGE_YOUNG | _PAGE_DIRTY)
  311. #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  312. _PAGE_YOUNG | _PAGE_DIRTY)
  313. #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_YOUNG | \
  314. _PAGE_PROTECT)
  315. /*
  316. * On s390 the page table entry has an invalid bit and a read-only bit.
  317. * Read permission implies execute permission and write permission
  318. * implies read permission.
  319. */
  320. /*xwr*/
  321. #define __P000 PAGE_NONE
  322. #define __P001 PAGE_READ
  323. #define __P010 PAGE_READ
  324. #define __P011 PAGE_READ
  325. #define __P100 PAGE_READ
  326. #define __P101 PAGE_READ
  327. #define __P110 PAGE_READ
  328. #define __P111 PAGE_READ
  329. #define __S000 PAGE_NONE
  330. #define __S001 PAGE_READ
  331. #define __S010 PAGE_WRITE
  332. #define __S011 PAGE_WRITE
  333. #define __S100 PAGE_READ
  334. #define __S101 PAGE_READ
  335. #define __S110 PAGE_WRITE
  336. #define __S111 PAGE_WRITE
  337. /*
  338. * Segment entry (large page) protection definitions.
  339. */
  340. #define SEGMENT_NONE __pgprot(_SEGMENT_ENTRY_INVALID | \
  341. _SEGMENT_ENTRY_PROTECT)
  342. #define SEGMENT_READ __pgprot(_SEGMENT_ENTRY_PROTECT | \
  343. _SEGMENT_ENTRY_READ)
  344. #define SEGMENT_WRITE __pgprot(_SEGMENT_ENTRY_READ | \
  345. _SEGMENT_ENTRY_WRITE)
  346. static inline int mm_has_pgste(struct mm_struct *mm)
  347. {
  348. #ifdef CONFIG_PGSTE
  349. if (unlikely(mm->context.has_pgste))
  350. return 1;
  351. #endif
  352. return 0;
  353. }
  354. static inline int mm_alloc_pgste(struct mm_struct *mm)
  355. {
  356. #ifdef CONFIG_PGSTE
  357. if (unlikely(mm->context.alloc_pgste))
  358. return 1;
  359. #endif
  360. return 0;
  361. }
  362. /*
  363. * In the case that a guest uses storage keys
  364. * faults should no longer be backed by zero pages
  365. */
  366. #define mm_forbids_zeropage mm_use_skey
  367. static inline int mm_use_skey(struct mm_struct *mm)
  368. {
  369. #ifdef CONFIG_PGSTE
  370. if (mm->context.use_skey)
  371. return 1;
  372. #endif
  373. return 0;
  374. }
  375. /*
  376. * pgd/pmd/pte query functions
  377. */
  378. static inline int pgd_present(pgd_t pgd)
  379. {
  380. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  381. return 1;
  382. return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL;
  383. }
  384. static inline int pgd_none(pgd_t pgd)
  385. {
  386. if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
  387. return 0;
  388. return (pgd_val(pgd) & _REGION_ENTRY_INVALID) != 0UL;
  389. }
  390. static inline int pgd_bad(pgd_t pgd)
  391. {
  392. /*
  393. * With dynamic page table levels the pgd can be a region table
  394. * entry or a segment table entry. Check for the bit that are
  395. * invalid for either table entry.
  396. */
  397. unsigned long mask =
  398. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INVALID &
  399. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  400. return (pgd_val(pgd) & mask) != 0;
  401. }
  402. static inline int pud_present(pud_t pud)
  403. {
  404. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  405. return 1;
  406. return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL;
  407. }
  408. static inline int pud_none(pud_t pud)
  409. {
  410. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3)
  411. return 0;
  412. return (pud_val(pud) & _REGION_ENTRY_INVALID) != 0UL;
  413. }
  414. static inline int pud_large(pud_t pud)
  415. {
  416. if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) != _REGION_ENTRY_TYPE_R3)
  417. return 0;
  418. return !!(pud_val(pud) & _REGION3_ENTRY_LARGE);
  419. }
  420. static inline int pud_bad(pud_t pud)
  421. {
  422. /*
  423. * With dynamic page table levels the pud can be a region table
  424. * entry or a segment table entry. Check for the bit that are
  425. * invalid for either table entry.
  426. */
  427. unsigned long mask =
  428. ~_SEGMENT_ENTRY_ORIGIN & ~_REGION_ENTRY_INVALID &
  429. ~_REGION_ENTRY_TYPE_MASK & ~_REGION_ENTRY_LENGTH;
  430. return (pud_val(pud) & mask) != 0;
  431. }
  432. static inline int pmd_present(pmd_t pmd)
  433. {
  434. return pmd_val(pmd) != _SEGMENT_ENTRY_INVALID;
  435. }
  436. static inline int pmd_none(pmd_t pmd)
  437. {
  438. return pmd_val(pmd) == _SEGMENT_ENTRY_INVALID;
  439. }
  440. static inline int pmd_large(pmd_t pmd)
  441. {
  442. return (pmd_val(pmd) & _SEGMENT_ENTRY_LARGE) != 0;
  443. }
  444. static inline unsigned long pmd_pfn(pmd_t pmd)
  445. {
  446. unsigned long origin_mask;
  447. origin_mask = _SEGMENT_ENTRY_ORIGIN;
  448. if (pmd_large(pmd))
  449. origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;
  450. return (pmd_val(pmd) & origin_mask) >> PAGE_SHIFT;
  451. }
  452. static inline int pmd_bad(pmd_t pmd)
  453. {
  454. if (pmd_large(pmd))
  455. return (pmd_val(pmd) & ~_SEGMENT_ENTRY_BITS_LARGE) != 0;
  456. return (pmd_val(pmd) & ~_SEGMENT_ENTRY_BITS) != 0;
  457. }
  458. #define __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  459. extern void pmdp_splitting_flush(struct vm_area_struct *vma,
  460. unsigned long addr, pmd_t *pmdp);
  461. #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
  462. extern int pmdp_set_access_flags(struct vm_area_struct *vma,
  463. unsigned long address, pmd_t *pmdp,
  464. pmd_t entry, int dirty);
  465. #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
  466. extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
  467. unsigned long address, pmd_t *pmdp);
  468. #define __HAVE_ARCH_PMD_WRITE
  469. static inline int pmd_write(pmd_t pmd)
  470. {
  471. return (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) != 0;
  472. }
  473. static inline int pmd_dirty(pmd_t pmd)
  474. {
  475. int dirty = 1;
  476. if (pmd_large(pmd))
  477. dirty = (pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY) != 0;
  478. return dirty;
  479. }
  480. static inline int pmd_young(pmd_t pmd)
  481. {
  482. int young = 1;
  483. if (pmd_large(pmd))
  484. young = (pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG) != 0;
  485. return young;
  486. }
  487. static inline int pte_present(pte_t pte)
  488. {
  489. /* Bit pattern: (pte & 0x001) == 0x001 */
  490. return (pte_val(pte) & _PAGE_PRESENT) != 0;
  491. }
  492. static inline int pte_none(pte_t pte)
  493. {
  494. /* Bit pattern: pte == 0x400 */
  495. return pte_val(pte) == _PAGE_INVALID;
  496. }
  497. static inline int pte_swap(pte_t pte)
  498. {
  499. /* Bit pattern: (pte & 0x201) == 0x200 */
  500. return (pte_val(pte) & (_PAGE_PROTECT | _PAGE_PRESENT))
  501. == _PAGE_PROTECT;
  502. }
  503. static inline int pte_special(pte_t pte)
  504. {
  505. return (pte_val(pte) & _PAGE_SPECIAL);
  506. }
  507. #define __HAVE_ARCH_PTE_SAME
  508. static inline int pte_same(pte_t a, pte_t b)
  509. {
  510. return pte_val(a) == pte_val(b);
  511. }
  512. static inline pgste_t pgste_get_lock(pte_t *ptep)
  513. {
  514. unsigned long new = 0;
  515. #ifdef CONFIG_PGSTE
  516. unsigned long old;
  517. preempt_disable();
  518. asm(
  519. " lg %0,%2\n"
  520. "0: lgr %1,%0\n"
  521. " nihh %0,0xff7f\n" /* clear PCL bit in old */
  522. " oihh %1,0x0080\n" /* set PCL bit in new */
  523. " csg %0,%1,%2\n"
  524. " jl 0b\n"
  525. : "=&d" (old), "=&d" (new), "=Q" (ptep[PTRS_PER_PTE])
  526. : "Q" (ptep[PTRS_PER_PTE]) : "cc", "memory");
  527. #endif
  528. return __pgste(new);
  529. }
  530. static inline void pgste_set_unlock(pte_t *ptep, pgste_t pgste)
  531. {
  532. #ifdef CONFIG_PGSTE
  533. asm(
  534. " nihh %1,0xff7f\n" /* clear PCL bit */
  535. " stg %1,%0\n"
  536. : "=Q" (ptep[PTRS_PER_PTE])
  537. : "d" (pgste_val(pgste)), "Q" (ptep[PTRS_PER_PTE])
  538. : "cc", "memory");
  539. preempt_enable();
  540. #endif
  541. }
  542. static inline pgste_t pgste_get(pte_t *ptep)
  543. {
  544. unsigned long pgste = 0;
  545. #ifdef CONFIG_PGSTE
  546. pgste = *(unsigned long *)(ptep + PTRS_PER_PTE);
  547. #endif
  548. return __pgste(pgste);
  549. }
  550. static inline void pgste_set(pte_t *ptep, pgste_t pgste)
  551. {
  552. #ifdef CONFIG_PGSTE
  553. *(pgste_t *)(ptep + PTRS_PER_PTE) = pgste;
  554. #endif
  555. }
  556. static inline pgste_t pgste_update_all(pte_t *ptep, pgste_t pgste,
  557. struct mm_struct *mm)
  558. {
  559. #ifdef CONFIG_PGSTE
  560. unsigned long address, bits, skey;
  561. if (!mm_use_skey(mm) || pte_val(*ptep) & _PAGE_INVALID)
  562. return pgste;
  563. address = pte_val(*ptep) & PAGE_MASK;
  564. skey = (unsigned long) page_get_storage_key(address);
  565. bits = skey & (_PAGE_CHANGED | _PAGE_REFERENCED);
  566. /* Transfer page changed & referenced bit to guest bits in pgste */
  567. pgste_val(pgste) |= bits << 48; /* GR bit & GC bit */
  568. /* Copy page access key and fetch protection bit to pgste */
  569. pgste_val(pgste) &= ~(PGSTE_ACC_BITS | PGSTE_FP_BIT);
  570. pgste_val(pgste) |= (skey & (_PAGE_ACC_BITS | _PAGE_FP_BIT)) << 56;
  571. #endif
  572. return pgste;
  573. }
  574. static inline void pgste_set_key(pte_t *ptep, pgste_t pgste, pte_t entry,
  575. struct mm_struct *mm)
  576. {
  577. #ifdef CONFIG_PGSTE
  578. unsigned long address;
  579. unsigned long nkey;
  580. if (!mm_use_skey(mm) || pte_val(entry) & _PAGE_INVALID)
  581. return;
  582. VM_BUG_ON(!(pte_val(*ptep) & _PAGE_INVALID));
  583. address = pte_val(entry) & PAGE_MASK;
  584. /*
  585. * Set page access key and fetch protection bit from pgste.
  586. * The guest C/R information is still in the PGSTE, set real
  587. * key C/R to 0.
  588. */
  589. nkey = (pgste_val(pgste) & (PGSTE_ACC_BITS | PGSTE_FP_BIT)) >> 56;
  590. nkey |= (pgste_val(pgste) & (PGSTE_GR_BIT | PGSTE_GC_BIT)) >> 48;
  591. page_set_storage_key(address, nkey, 0);
  592. #endif
  593. }
  594. static inline pgste_t pgste_set_pte(pte_t *ptep, pgste_t pgste, pte_t entry)
  595. {
  596. if ((pte_val(entry) & _PAGE_PRESENT) &&
  597. (pte_val(entry) & _PAGE_WRITE) &&
  598. !(pte_val(entry) & _PAGE_INVALID)) {
  599. if (!MACHINE_HAS_ESOP) {
  600. /*
  601. * Without enhanced suppression-on-protection force
  602. * the dirty bit on for all writable ptes.
  603. */
  604. pte_val(entry) |= _PAGE_DIRTY;
  605. pte_val(entry) &= ~_PAGE_PROTECT;
  606. }
  607. if (!(pte_val(entry) & _PAGE_PROTECT))
  608. /* This pte allows write access, set user-dirty */
  609. pgste_val(pgste) |= PGSTE_UC_BIT;
  610. }
  611. *ptep = entry;
  612. return pgste;
  613. }
  614. /**
  615. * struct gmap_struct - guest address space
  616. * @crst_list: list of all crst tables used in the guest address space
  617. * @mm: pointer to the parent mm_struct
  618. * @guest_to_host: radix tree with guest to host address translation
  619. * @host_to_guest: radix tree with pointer to segment table entries
  620. * @guest_table_lock: spinlock to protect all entries in the guest page table
  621. * @table: pointer to the page directory
  622. * @asce: address space control element for gmap page table
  623. * @pfault_enabled: defines if pfaults are applicable for the guest
  624. */
  625. struct gmap {
  626. struct list_head list;
  627. struct list_head crst_list;
  628. struct mm_struct *mm;
  629. struct radix_tree_root guest_to_host;
  630. struct radix_tree_root host_to_guest;
  631. spinlock_t guest_table_lock;
  632. unsigned long *table;
  633. unsigned long asce;
  634. unsigned long asce_end;
  635. void *private;
  636. bool pfault_enabled;
  637. };
  638. /**
  639. * struct gmap_notifier - notify function block for page invalidation
  640. * @notifier_call: address of callback function
  641. */
  642. struct gmap_notifier {
  643. struct list_head list;
  644. void (*notifier_call)(struct gmap *gmap, unsigned long gaddr);
  645. };
  646. struct gmap *gmap_alloc(struct mm_struct *mm, unsigned long limit);
  647. void gmap_free(struct gmap *gmap);
  648. void gmap_enable(struct gmap *gmap);
  649. void gmap_disable(struct gmap *gmap);
  650. int gmap_map_segment(struct gmap *gmap, unsigned long from,
  651. unsigned long to, unsigned long len);
  652. int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
  653. unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
  654. unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
  655. int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
  656. int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
  657. void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
  658. void __gmap_zap(struct gmap *, unsigned long gaddr);
  659. bool gmap_test_and_clear_dirty(unsigned long address, struct gmap *);
  660. void gmap_register_ipte_notifier(struct gmap_notifier *);
  661. void gmap_unregister_ipte_notifier(struct gmap_notifier *);
  662. int gmap_ipte_notify(struct gmap *, unsigned long start, unsigned long len);
  663. void gmap_do_ipte_notify(struct mm_struct *, unsigned long addr, pte_t *);
  664. static inline pgste_t pgste_ipte_notify(struct mm_struct *mm,
  665. unsigned long addr,
  666. pte_t *ptep, pgste_t pgste)
  667. {
  668. #ifdef CONFIG_PGSTE
  669. if (pgste_val(pgste) & PGSTE_IN_BIT) {
  670. pgste_val(pgste) &= ~PGSTE_IN_BIT;
  671. gmap_do_ipte_notify(mm, addr, ptep);
  672. }
  673. #endif
  674. return pgste;
  675. }
  676. /*
  677. * Certain architectures need to do special things when PTEs
  678. * within a page table are directly modified. Thus, the following
  679. * hook is made available.
  680. */
  681. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  682. pte_t *ptep, pte_t entry)
  683. {
  684. pgste_t pgste;
  685. if (mm_has_pgste(mm)) {
  686. pgste = pgste_get_lock(ptep);
  687. pgste_val(pgste) &= ~_PGSTE_GPS_ZERO;
  688. pgste_set_key(ptep, pgste, entry, mm);
  689. pgste = pgste_set_pte(ptep, pgste, entry);
  690. pgste_set_unlock(ptep, pgste);
  691. } else {
  692. *ptep = entry;
  693. }
  694. }
  695. /*
  696. * query functions pte_write/pte_dirty/pte_young only work if
  697. * pte_present() is true. Undefined behaviour if not..
  698. */
  699. static inline int pte_write(pte_t pte)
  700. {
  701. return (pte_val(pte) & _PAGE_WRITE) != 0;
  702. }
  703. static inline int pte_dirty(pte_t pte)
  704. {
  705. return (pte_val(pte) & _PAGE_DIRTY) != 0;
  706. }
  707. static inline int pte_young(pte_t pte)
  708. {
  709. return (pte_val(pte) & _PAGE_YOUNG) != 0;
  710. }
  711. #define __HAVE_ARCH_PTE_UNUSED
  712. static inline int pte_unused(pte_t pte)
  713. {
  714. return pte_val(pte) & _PAGE_UNUSED;
  715. }
  716. /*
  717. * pgd/pmd/pte modification functions
  718. */
  719. static inline void pgd_clear(pgd_t *pgd)
  720. {
  721. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  722. pgd_val(*pgd) = _REGION2_ENTRY_EMPTY;
  723. }
  724. static inline void pud_clear(pud_t *pud)
  725. {
  726. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  727. pud_val(*pud) = _REGION3_ENTRY_EMPTY;
  728. }
  729. static inline void pmd_clear(pmd_t *pmdp)
  730. {
  731. pmd_val(*pmdp) = _SEGMENT_ENTRY_INVALID;
  732. }
  733. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  734. {
  735. pte_val(*ptep) = _PAGE_INVALID;
  736. }
  737. /*
  738. * The following pte modification functions only work if
  739. * pte_present() is true. Undefined behaviour if not..
  740. */
  741. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  742. {
  743. pte_val(pte) &= _PAGE_CHG_MASK;
  744. pte_val(pte) |= pgprot_val(newprot);
  745. /*
  746. * newprot for PAGE_NONE, PAGE_READ and PAGE_WRITE has the
  747. * invalid bit set, clear it again for readable, young pages
  748. */
  749. if ((pte_val(pte) & _PAGE_YOUNG) && (pte_val(pte) & _PAGE_READ))
  750. pte_val(pte) &= ~_PAGE_INVALID;
  751. /*
  752. * newprot for PAGE_READ and PAGE_WRITE has the page protection
  753. * bit set, clear it again for writable, dirty pages
  754. */
  755. if ((pte_val(pte) & _PAGE_DIRTY) && (pte_val(pte) & _PAGE_WRITE))
  756. pte_val(pte) &= ~_PAGE_PROTECT;
  757. return pte;
  758. }
  759. static inline pte_t pte_wrprotect(pte_t pte)
  760. {
  761. pte_val(pte) &= ~_PAGE_WRITE;
  762. pte_val(pte) |= _PAGE_PROTECT;
  763. return pte;
  764. }
  765. static inline pte_t pte_mkwrite(pte_t pte)
  766. {
  767. pte_val(pte) |= _PAGE_WRITE;
  768. if (pte_val(pte) & _PAGE_DIRTY)
  769. pte_val(pte) &= ~_PAGE_PROTECT;
  770. return pte;
  771. }
  772. static inline pte_t pte_mkclean(pte_t pte)
  773. {
  774. pte_val(pte) &= ~_PAGE_DIRTY;
  775. pte_val(pte) |= _PAGE_PROTECT;
  776. return pte;
  777. }
  778. static inline pte_t pte_mkdirty(pte_t pte)
  779. {
  780. pte_val(pte) |= _PAGE_DIRTY;
  781. if (pte_val(pte) & _PAGE_WRITE)
  782. pte_val(pte) &= ~_PAGE_PROTECT;
  783. return pte;
  784. }
  785. static inline pte_t pte_mkold(pte_t pte)
  786. {
  787. pte_val(pte) &= ~_PAGE_YOUNG;
  788. pte_val(pte) |= _PAGE_INVALID;
  789. return pte;
  790. }
  791. static inline pte_t pte_mkyoung(pte_t pte)
  792. {
  793. pte_val(pte) |= _PAGE_YOUNG;
  794. if (pte_val(pte) & _PAGE_READ)
  795. pte_val(pte) &= ~_PAGE_INVALID;
  796. return pte;
  797. }
  798. static inline pte_t pte_mkspecial(pte_t pte)
  799. {
  800. pte_val(pte) |= _PAGE_SPECIAL;
  801. return pte;
  802. }
  803. #ifdef CONFIG_HUGETLB_PAGE
  804. static inline pte_t pte_mkhuge(pte_t pte)
  805. {
  806. pte_val(pte) |= _PAGE_LARGE;
  807. return pte;
  808. }
  809. #endif
  810. static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
  811. {
  812. unsigned long pto = (unsigned long) ptep;
  813. /* Invalidation + global TLB flush for the pte */
  814. asm volatile(
  815. " ipte %2,%3"
  816. : "=m" (*ptep) : "m" (*ptep), "a" (pto), "a" (address));
  817. }
  818. static inline void __ptep_ipte_local(unsigned long address, pte_t *ptep)
  819. {
  820. unsigned long pto = (unsigned long) ptep;
  821. /* Invalidation + local TLB flush for the pte */
  822. asm volatile(
  823. " .insn rrf,0xb2210000,%2,%3,0,1"
  824. : "=m" (*ptep) : "m" (*ptep), "a" (pto), "a" (address));
  825. }
  826. static inline void __ptep_ipte_range(unsigned long address, int nr, pte_t *ptep)
  827. {
  828. unsigned long pto = (unsigned long) ptep;
  829. /* Invalidate a range of ptes + global TLB flush of the ptes */
  830. do {
  831. asm volatile(
  832. " .insn rrf,0xb2210000,%2,%0,%1,0"
  833. : "+a" (address), "+a" (nr) : "a" (pto) : "memory");
  834. } while (nr != 255);
  835. }
  836. static inline void ptep_flush_direct(struct mm_struct *mm,
  837. unsigned long address, pte_t *ptep)
  838. {
  839. int active, count;
  840. if (pte_val(*ptep) & _PAGE_INVALID)
  841. return;
  842. active = (mm == current->active_mm) ? 1 : 0;
  843. count = atomic_add_return(0x10000, &mm->context.attach_count);
  844. if (MACHINE_HAS_TLB_LC && (count & 0xffff) <= active &&
  845. cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id())))
  846. __ptep_ipte_local(address, ptep);
  847. else
  848. __ptep_ipte(address, ptep);
  849. atomic_sub(0x10000, &mm->context.attach_count);
  850. }
  851. static inline void ptep_flush_lazy(struct mm_struct *mm,
  852. unsigned long address, pte_t *ptep)
  853. {
  854. int active, count;
  855. if (pte_val(*ptep) & _PAGE_INVALID)
  856. return;
  857. active = (mm == current->active_mm) ? 1 : 0;
  858. count = atomic_add_return(0x10000, &mm->context.attach_count);
  859. if ((count & 0xffff) <= active) {
  860. pte_val(*ptep) |= _PAGE_INVALID;
  861. mm->context.flush_mm = 1;
  862. } else
  863. __ptep_ipte(address, ptep);
  864. atomic_sub(0x10000, &mm->context.attach_count);
  865. }
  866. /*
  867. * Get (and clear) the user dirty bit for a pte.
  868. */
  869. static inline int ptep_test_and_clear_user_dirty(struct mm_struct *mm,
  870. unsigned long addr,
  871. pte_t *ptep)
  872. {
  873. pgste_t pgste;
  874. pte_t pte;
  875. int dirty;
  876. if (!mm_has_pgste(mm))
  877. return 0;
  878. pgste = pgste_get_lock(ptep);
  879. dirty = !!(pgste_val(pgste) & PGSTE_UC_BIT);
  880. pgste_val(pgste) &= ~PGSTE_UC_BIT;
  881. pte = *ptep;
  882. if (dirty && (pte_val(pte) & _PAGE_PRESENT)) {
  883. pgste = pgste_ipte_notify(mm, addr, ptep, pgste);
  884. __ptep_ipte(addr, ptep);
  885. if (MACHINE_HAS_ESOP || !(pte_val(pte) & _PAGE_WRITE))
  886. pte_val(pte) |= _PAGE_PROTECT;
  887. else
  888. pte_val(pte) |= _PAGE_INVALID;
  889. *ptep = pte;
  890. }
  891. pgste_set_unlock(ptep, pgste);
  892. return dirty;
  893. }
  894. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  895. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  896. unsigned long addr, pte_t *ptep)
  897. {
  898. pgste_t pgste;
  899. pte_t pte, oldpte;
  900. int young;
  901. if (mm_has_pgste(vma->vm_mm)) {
  902. pgste = pgste_get_lock(ptep);
  903. pgste = pgste_ipte_notify(vma->vm_mm, addr, ptep, pgste);
  904. }
  905. oldpte = pte = *ptep;
  906. ptep_flush_direct(vma->vm_mm, addr, ptep);
  907. young = pte_young(pte);
  908. pte = pte_mkold(pte);
  909. if (mm_has_pgste(vma->vm_mm)) {
  910. pgste = pgste_update_all(&oldpte, pgste, vma->vm_mm);
  911. pgste = pgste_set_pte(ptep, pgste, pte);
  912. pgste_set_unlock(ptep, pgste);
  913. } else
  914. *ptep = pte;
  915. return young;
  916. }
  917. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  918. static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  919. unsigned long address, pte_t *ptep)
  920. {
  921. return ptep_test_and_clear_young(vma, address, ptep);
  922. }
  923. /*
  924. * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
  925. * both clear the TLB for the unmapped pte. The reason is that
  926. * ptep_get_and_clear is used in common code (e.g. change_pte_range)
  927. * to modify an active pte. The sequence is
  928. * 1) ptep_get_and_clear
  929. * 2) set_pte_at
  930. * 3) flush_tlb_range
  931. * On s390 the tlb needs to get flushed with the modification of the pte
  932. * if the pte is active. The only way how this can be implemented is to
  933. * have ptep_get_and_clear do the tlb flush. In exchange flush_tlb_range
  934. * is a nop.
  935. */
  936. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  937. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  938. unsigned long address, pte_t *ptep)
  939. {
  940. pgste_t pgste;
  941. pte_t pte;
  942. if (mm_has_pgste(mm)) {
  943. pgste = pgste_get_lock(ptep);
  944. pgste = pgste_ipte_notify(mm, address, ptep, pgste);
  945. }
  946. pte = *ptep;
  947. ptep_flush_lazy(mm, address, ptep);
  948. pte_val(*ptep) = _PAGE_INVALID;
  949. if (mm_has_pgste(mm)) {
  950. pgste = pgste_update_all(&pte, pgste, mm);
  951. pgste_set_unlock(ptep, pgste);
  952. }
  953. return pte;
  954. }
  955. #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
  956. static inline pte_t ptep_modify_prot_start(struct mm_struct *mm,
  957. unsigned long address,
  958. pte_t *ptep)
  959. {
  960. pgste_t pgste;
  961. pte_t pte;
  962. if (mm_has_pgste(mm)) {
  963. pgste = pgste_get_lock(ptep);
  964. pgste_ipte_notify(mm, address, ptep, pgste);
  965. }
  966. pte = *ptep;
  967. ptep_flush_lazy(mm, address, ptep);
  968. if (mm_has_pgste(mm)) {
  969. pgste = pgste_update_all(&pte, pgste, mm);
  970. pgste_set(ptep, pgste);
  971. }
  972. return pte;
  973. }
  974. static inline void ptep_modify_prot_commit(struct mm_struct *mm,
  975. unsigned long address,
  976. pte_t *ptep, pte_t pte)
  977. {
  978. pgste_t pgste;
  979. if (mm_has_pgste(mm)) {
  980. pgste = pgste_get(ptep);
  981. pgste_set_key(ptep, pgste, pte, mm);
  982. pgste = pgste_set_pte(ptep, pgste, pte);
  983. pgste_set_unlock(ptep, pgste);
  984. } else
  985. *ptep = pte;
  986. }
  987. #define __HAVE_ARCH_PTEP_CLEAR_FLUSH
  988. static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
  989. unsigned long address, pte_t *ptep)
  990. {
  991. pgste_t pgste;
  992. pte_t pte;
  993. if (mm_has_pgste(vma->vm_mm)) {
  994. pgste = pgste_get_lock(ptep);
  995. pgste = pgste_ipte_notify(vma->vm_mm, address, ptep, pgste);
  996. }
  997. pte = *ptep;
  998. ptep_flush_direct(vma->vm_mm, address, ptep);
  999. pte_val(*ptep) = _PAGE_INVALID;
  1000. if (mm_has_pgste(vma->vm_mm)) {
  1001. if ((pgste_val(pgste) & _PGSTE_GPS_USAGE_MASK) ==
  1002. _PGSTE_GPS_USAGE_UNUSED)
  1003. pte_val(pte) |= _PAGE_UNUSED;
  1004. pgste = pgste_update_all(&pte, pgste, vma->vm_mm);
  1005. pgste_set_unlock(ptep, pgste);
  1006. }
  1007. return pte;
  1008. }
  1009. /*
  1010. * The batched pte unmap code uses ptep_get_and_clear_full to clear the
  1011. * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
  1012. * tlbs of an mm if it can guarantee that the ptes of the mm_struct
  1013. * cannot be accessed while the batched unmap is running. In this case
  1014. * full==1 and a simple pte_clear is enough. See tlb.h.
  1015. */
  1016. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
  1017. static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
  1018. unsigned long address,
  1019. pte_t *ptep, int full)
  1020. {
  1021. pgste_t pgste;
  1022. pte_t pte;
  1023. if (!full && mm_has_pgste(mm)) {
  1024. pgste = pgste_get_lock(ptep);
  1025. pgste = pgste_ipte_notify(mm, address, ptep, pgste);
  1026. }
  1027. pte = *ptep;
  1028. if (!full)
  1029. ptep_flush_lazy(mm, address, ptep);
  1030. pte_val(*ptep) = _PAGE_INVALID;
  1031. if (!full && mm_has_pgste(mm)) {
  1032. pgste = pgste_update_all(&pte, pgste, mm);
  1033. pgste_set_unlock(ptep, pgste);
  1034. }
  1035. return pte;
  1036. }
  1037. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  1038. static inline pte_t ptep_set_wrprotect(struct mm_struct *mm,
  1039. unsigned long address, pte_t *ptep)
  1040. {
  1041. pgste_t pgste;
  1042. pte_t pte = *ptep;
  1043. if (pte_write(pte)) {
  1044. if (mm_has_pgste(mm)) {
  1045. pgste = pgste_get_lock(ptep);
  1046. pgste = pgste_ipte_notify(mm, address, ptep, pgste);
  1047. }
  1048. ptep_flush_lazy(mm, address, ptep);
  1049. pte = pte_wrprotect(pte);
  1050. if (mm_has_pgste(mm)) {
  1051. pgste = pgste_set_pte(ptep, pgste, pte);
  1052. pgste_set_unlock(ptep, pgste);
  1053. } else
  1054. *ptep = pte;
  1055. }
  1056. return pte;
  1057. }
  1058. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  1059. static inline int ptep_set_access_flags(struct vm_area_struct *vma,
  1060. unsigned long address, pte_t *ptep,
  1061. pte_t entry, int dirty)
  1062. {
  1063. pgste_t pgste;
  1064. if (pte_same(*ptep, entry))
  1065. return 0;
  1066. if (mm_has_pgste(vma->vm_mm)) {
  1067. pgste = pgste_get_lock(ptep);
  1068. pgste = pgste_ipte_notify(vma->vm_mm, address, ptep, pgste);
  1069. }
  1070. ptep_flush_direct(vma->vm_mm, address, ptep);
  1071. if (mm_has_pgste(vma->vm_mm)) {
  1072. pgste_set_key(ptep, pgste, entry, vma->vm_mm);
  1073. pgste = pgste_set_pte(ptep, pgste, entry);
  1074. pgste_set_unlock(ptep, pgste);
  1075. } else
  1076. *ptep = entry;
  1077. return 1;
  1078. }
  1079. /*
  1080. * Conversion functions: convert a page and protection to a page entry,
  1081. * and a page entry and page directory to the page they refer to.
  1082. */
  1083. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  1084. {
  1085. pte_t __pte;
  1086. pte_val(__pte) = physpage + pgprot_val(pgprot);
  1087. return pte_mkyoung(__pte);
  1088. }
  1089. static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
  1090. {
  1091. unsigned long physpage = page_to_phys(page);
  1092. pte_t __pte = mk_pte_phys(physpage, pgprot);
  1093. if (pte_write(__pte) && PageDirty(page))
  1094. __pte = pte_mkdirty(__pte);
  1095. return __pte;
  1096. }
  1097. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  1098. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  1099. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  1100. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
  1101. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  1102. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  1103. #define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
  1104. #define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
  1105. #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
  1106. static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  1107. {
  1108. pud_t *pud = (pud_t *) pgd;
  1109. if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
  1110. pud = (pud_t *) pgd_deref(*pgd);
  1111. return pud + pud_index(address);
  1112. }
  1113. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  1114. {
  1115. pmd_t *pmd = (pmd_t *) pud;
  1116. if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
  1117. pmd = (pmd_t *) pud_deref(*pud);
  1118. return pmd + pmd_index(address);
  1119. }
  1120. #define pfn_pte(pfn,pgprot) mk_pte_phys(__pa((pfn) << PAGE_SHIFT),(pgprot))
  1121. #define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
  1122. #define pte_page(x) pfn_to_page(pte_pfn(x))
  1123. #define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd))
  1124. /* Find an entry in the lowest level page table.. */
  1125. #define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
  1126. #define pte_offset_kernel(pmd, address) pte_offset(pmd,address)
  1127. #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
  1128. #define pte_unmap(pte) do { } while (0)
  1129. #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE)
  1130. static inline unsigned long massage_pgprot_pmd(pgprot_t pgprot)
  1131. {
  1132. /*
  1133. * pgprot is PAGE_NONE, PAGE_READ, or PAGE_WRITE (see __Pxxx / __Sxxx)
  1134. * Convert to segment table entry format.
  1135. */
  1136. if (pgprot_val(pgprot) == pgprot_val(PAGE_NONE))
  1137. return pgprot_val(SEGMENT_NONE);
  1138. if (pgprot_val(pgprot) == pgprot_val(PAGE_READ))
  1139. return pgprot_val(SEGMENT_READ);
  1140. return pgprot_val(SEGMENT_WRITE);
  1141. }
  1142. static inline pmd_t pmd_wrprotect(pmd_t pmd)
  1143. {
  1144. pmd_val(pmd) &= ~_SEGMENT_ENTRY_WRITE;
  1145. pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
  1146. return pmd;
  1147. }
  1148. static inline pmd_t pmd_mkwrite(pmd_t pmd)
  1149. {
  1150. pmd_val(pmd) |= _SEGMENT_ENTRY_WRITE;
  1151. if (pmd_large(pmd) && !(pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY))
  1152. return pmd;
  1153. pmd_val(pmd) &= ~_SEGMENT_ENTRY_PROTECT;
  1154. return pmd;
  1155. }
  1156. static inline pmd_t pmd_mkclean(pmd_t pmd)
  1157. {
  1158. if (pmd_large(pmd)) {
  1159. pmd_val(pmd) &= ~_SEGMENT_ENTRY_DIRTY;
  1160. pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
  1161. }
  1162. return pmd;
  1163. }
  1164. static inline pmd_t pmd_mkdirty(pmd_t pmd)
  1165. {
  1166. if (pmd_large(pmd)) {
  1167. pmd_val(pmd) |= _SEGMENT_ENTRY_DIRTY;
  1168. if (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE)
  1169. pmd_val(pmd) &= ~_SEGMENT_ENTRY_PROTECT;
  1170. }
  1171. return pmd;
  1172. }
  1173. static inline pmd_t pmd_mkyoung(pmd_t pmd)
  1174. {
  1175. if (pmd_large(pmd)) {
  1176. pmd_val(pmd) |= _SEGMENT_ENTRY_YOUNG;
  1177. if (pmd_val(pmd) & _SEGMENT_ENTRY_READ)
  1178. pmd_val(pmd) &= ~_SEGMENT_ENTRY_INVALID;
  1179. }
  1180. return pmd;
  1181. }
  1182. static inline pmd_t pmd_mkold(pmd_t pmd)
  1183. {
  1184. if (pmd_large(pmd)) {
  1185. pmd_val(pmd) &= ~_SEGMENT_ENTRY_YOUNG;
  1186. pmd_val(pmd) |= _SEGMENT_ENTRY_INVALID;
  1187. }
  1188. return pmd;
  1189. }
  1190. static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
  1191. {
  1192. if (pmd_large(pmd)) {
  1193. pmd_val(pmd) &= _SEGMENT_ENTRY_ORIGIN_LARGE |
  1194. _SEGMENT_ENTRY_DIRTY | _SEGMENT_ENTRY_YOUNG |
  1195. _SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_SPLIT;
  1196. pmd_val(pmd) |= massage_pgprot_pmd(newprot);
  1197. if (!(pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY))
  1198. pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
  1199. if (!(pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG))
  1200. pmd_val(pmd) |= _SEGMENT_ENTRY_INVALID;
  1201. return pmd;
  1202. }
  1203. pmd_val(pmd) &= _SEGMENT_ENTRY_ORIGIN;
  1204. pmd_val(pmd) |= massage_pgprot_pmd(newprot);
  1205. return pmd;
  1206. }
  1207. static inline pmd_t mk_pmd_phys(unsigned long physpage, pgprot_t pgprot)
  1208. {
  1209. pmd_t __pmd;
  1210. pmd_val(__pmd) = physpage + massage_pgprot_pmd(pgprot);
  1211. return __pmd;
  1212. }
  1213. #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLB_PAGE */
  1214. static inline void __pmdp_csp(pmd_t *pmdp)
  1215. {
  1216. register unsigned long reg2 asm("2") = pmd_val(*pmdp);
  1217. register unsigned long reg3 asm("3") = pmd_val(*pmdp) |
  1218. _SEGMENT_ENTRY_INVALID;
  1219. register unsigned long reg4 asm("4") = ((unsigned long) pmdp) + 5;
  1220. asm volatile(
  1221. " csp %1,%3"
  1222. : "=m" (*pmdp)
  1223. : "d" (reg2), "d" (reg3), "d" (reg4), "m" (*pmdp) : "cc");
  1224. }
  1225. static inline void __pmdp_idte(unsigned long address, pmd_t *pmdp)
  1226. {
  1227. unsigned long sto;
  1228. sto = (unsigned long) pmdp - pmd_index(address) * sizeof(pmd_t);
  1229. asm volatile(
  1230. " .insn rrf,0xb98e0000,%2,%3,0,0"
  1231. : "=m" (*pmdp)
  1232. : "m" (*pmdp), "a" (sto), "a" ((address & HPAGE_MASK))
  1233. : "cc" );
  1234. }
  1235. static inline void __pmdp_idte_local(unsigned long address, pmd_t *pmdp)
  1236. {
  1237. unsigned long sto;
  1238. sto = (unsigned long) pmdp - pmd_index(address) * sizeof(pmd_t);
  1239. asm volatile(
  1240. " .insn rrf,0xb98e0000,%2,%3,0,1"
  1241. : "=m" (*pmdp)
  1242. : "m" (*pmdp), "a" (sto), "a" ((address & HPAGE_MASK))
  1243. : "cc" );
  1244. }
  1245. static inline void pmdp_flush_direct(struct mm_struct *mm,
  1246. unsigned long address, pmd_t *pmdp)
  1247. {
  1248. int active, count;
  1249. if (pmd_val(*pmdp) & _SEGMENT_ENTRY_INVALID)
  1250. return;
  1251. if (!MACHINE_HAS_IDTE) {
  1252. __pmdp_csp(pmdp);
  1253. return;
  1254. }
  1255. active = (mm == current->active_mm) ? 1 : 0;
  1256. count = atomic_add_return(0x10000, &mm->context.attach_count);
  1257. if (MACHINE_HAS_TLB_LC && (count & 0xffff) <= active &&
  1258. cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id())))
  1259. __pmdp_idte_local(address, pmdp);
  1260. else
  1261. __pmdp_idte(address, pmdp);
  1262. atomic_sub(0x10000, &mm->context.attach_count);
  1263. }
  1264. static inline void pmdp_flush_lazy(struct mm_struct *mm,
  1265. unsigned long address, pmd_t *pmdp)
  1266. {
  1267. int active, count;
  1268. if (pmd_val(*pmdp) & _SEGMENT_ENTRY_INVALID)
  1269. return;
  1270. active = (mm == current->active_mm) ? 1 : 0;
  1271. count = atomic_add_return(0x10000, &mm->context.attach_count);
  1272. if ((count & 0xffff) <= active) {
  1273. pmd_val(*pmdp) |= _SEGMENT_ENTRY_INVALID;
  1274. mm->context.flush_mm = 1;
  1275. } else if (MACHINE_HAS_IDTE)
  1276. __pmdp_idte(address, pmdp);
  1277. else
  1278. __pmdp_csp(pmdp);
  1279. atomic_sub(0x10000, &mm->context.attach_count);
  1280. }
  1281. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  1282. #define __HAVE_ARCH_PGTABLE_DEPOSIT
  1283. extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  1284. pgtable_t pgtable);
  1285. #define __HAVE_ARCH_PGTABLE_WITHDRAW
  1286. extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
  1287. static inline int pmd_trans_splitting(pmd_t pmd)
  1288. {
  1289. return (pmd_val(pmd) & _SEGMENT_ENTRY_LARGE) &&
  1290. (pmd_val(pmd) & _SEGMENT_ENTRY_SPLIT);
  1291. }
  1292. static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  1293. pmd_t *pmdp, pmd_t entry)
  1294. {
  1295. *pmdp = entry;
  1296. }
  1297. static inline pmd_t pmd_mkhuge(pmd_t pmd)
  1298. {
  1299. pmd_val(pmd) |= _SEGMENT_ENTRY_LARGE;
  1300. pmd_val(pmd) |= _SEGMENT_ENTRY_YOUNG;
  1301. pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
  1302. return pmd;
  1303. }
  1304. #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
  1305. static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
  1306. unsigned long address, pmd_t *pmdp)
  1307. {
  1308. pmd_t pmd;
  1309. pmd = *pmdp;
  1310. pmdp_flush_direct(vma->vm_mm, address, pmdp);
  1311. *pmdp = pmd_mkold(pmd);
  1312. return pmd_young(pmd);
  1313. }
  1314. #define __HAVE_ARCH_PMDP_GET_AND_CLEAR
  1315. static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm,
  1316. unsigned long address, pmd_t *pmdp)
  1317. {
  1318. pmd_t pmd = *pmdp;
  1319. pmdp_flush_direct(mm, address, pmdp);
  1320. pmd_clear(pmdp);
  1321. return pmd;
  1322. }
  1323. #define __HAVE_ARCH_PMDP_GET_AND_CLEAR_FULL
  1324. static inline pmd_t pmdp_get_and_clear_full(struct mm_struct *mm,
  1325. unsigned long address,
  1326. pmd_t *pmdp, int full)
  1327. {
  1328. pmd_t pmd = *pmdp;
  1329. if (!full)
  1330. pmdp_flush_lazy(mm, address, pmdp);
  1331. pmd_clear(pmdp);
  1332. return pmd;
  1333. }
  1334. #define __HAVE_ARCH_PMDP_CLEAR_FLUSH
  1335. static inline pmd_t pmdp_clear_flush(struct vm_area_struct *vma,
  1336. unsigned long address, pmd_t *pmdp)
  1337. {
  1338. return pmdp_get_and_clear(vma->vm_mm, address, pmdp);
  1339. }
  1340. #define __HAVE_ARCH_PMDP_INVALIDATE
  1341. static inline void pmdp_invalidate(struct vm_area_struct *vma,
  1342. unsigned long address, pmd_t *pmdp)
  1343. {
  1344. pmdp_flush_direct(vma->vm_mm, address, pmdp);
  1345. }
  1346. #define __HAVE_ARCH_PMDP_SET_WRPROTECT
  1347. static inline void pmdp_set_wrprotect(struct mm_struct *mm,
  1348. unsigned long address, pmd_t *pmdp)
  1349. {
  1350. pmd_t pmd = *pmdp;
  1351. if (pmd_write(pmd)) {
  1352. pmdp_flush_direct(mm, address, pmdp);
  1353. set_pmd_at(mm, address, pmdp, pmd_wrprotect(pmd));
  1354. }
  1355. }
  1356. #define pfn_pmd(pfn, pgprot) mk_pmd_phys(__pa((pfn) << PAGE_SHIFT), (pgprot))
  1357. #define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))
  1358. static inline int pmd_trans_huge(pmd_t pmd)
  1359. {
  1360. return pmd_val(pmd) & _SEGMENT_ENTRY_LARGE;
  1361. }
  1362. static inline int has_transparent_hugepage(void)
  1363. {
  1364. return MACHINE_HAS_HPAGE ? 1 : 0;
  1365. }
  1366. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  1367. /*
  1368. * 64 bit swap entry format:
  1369. * A page-table entry has some bits we have to treat in a special way.
  1370. * Bits 52 and bit 55 have to be zero, otherwise an specification
  1371. * exception will occur instead of a page translation exception. The
  1372. * specifiation exception has the bad habit not to store necessary
  1373. * information in the lowcore.
  1374. * Bits 54 and 63 are used to indicate the page type.
  1375. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200
  1376. * This leaves the bits 0-51 and bits 56-62 to store type and offset.
  1377. * We use the 5 bits from 57-61 for the type and the 52 bits from 0-51
  1378. * for the offset.
  1379. * | offset |01100|type |00|
  1380. * |0000000000111111111122222222223333333333444444444455|55555|55566|66|
  1381. * |0123456789012345678901234567890123456789012345678901|23456|78901|23|
  1382. */
  1383. #define __SWP_OFFSET_MASK ((1UL << 52) - 1)
  1384. #define __SWP_OFFSET_SHIFT 12
  1385. #define __SWP_TYPE_MASK ((1UL << 5) - 1)
  1386. #define __SWP_TYPE_SHIFT 2
  1387. static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  1388. {
  1389. pte_t pte;
  1390. pte_val(pte) = _PAGE_INVALID | _PAGE_PROTECT;
  1391. pte_val(pte) |= (offset & __SWP_OFFSET_MASK) << __SWP_OFFSET_SHIFT;
  1392. pte_val(pte) |= (type & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT;
  1393. return pte;
  1394. }
  1395. static inline unsigned long __swp_type(swp_entry_t entry)
  1396. {
  1397. return (entry.val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK;
  1398. }
  1399. static inline unsigned long __swp_offset(swp_entry_t entry)
  1400. {
  1401. return (entry.val >> __SWP_OFFSET_SHIFT) & __SWP_OFFSET_MASK;
  1402. }
  1403. static inline swp_entry_t __swp_entry(unsigned long type, unsigned long offset)
  1404. {
  1405. return (swp_entry_t) { pte_val(mk_swap_pte(type, offset)) };
  1406. }
  1407. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  1408. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  1409. #endif /* !__ASSEMBLY__ */
  1410. #define kern_addr_valid(addr) (1)
  1411. extern int vmem_add_mapping(unsigned long start, unsigned long size);
  1412. extern int vmem_remove_mapping(unsigned long start, unsigned long size);
  1413. extern int s390_enable_sie(void);
  1414. extern int s390_enable_skey(void);
  1415. extern void s390_reset_cmma(struct mm_struct *mm);
  1416. /* s390 has a private copy of get unmapped area to deal with cache synonyms */
  1417. #define HAVE_ARCH_UNMAPPED_AREA
  1418. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  1419. /*
  1420. * No page table caches to initialise
  1421. */
  1422. static inline void pgtable_cache_init(void) { }
  1423. static inline void check_pgt_cache(void) { }
  1424. #include <asm-generic/pgtable.h>
  1425. #endif /* _S390_PAGE_H */