pgtable.h 51 KB

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