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