pgtable.h 48 KB

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