pgtable.h 50 KB

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