pgtable.h 51 KB

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