entry.S 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  1. /*
  2. * S390 low-level entry points.
  3. *
  4. * Copyright IBM Corp. 1999, 2012
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  6. * Hartmut Penner (hp@de.ibm.com),
  7. * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
  8. * Heiko Carstens <heiko.carstens@de.ibm.com>
  9. */
  10. #include <linux/init.h>
  11. #include <linux/linkage.h>
  12. #include <asm/processor.h>
  13. #include <asm/cache.h>
  14. #include <asm/errno.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/thread_info.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/unistd.h>
  19. #include <asm/page.h>
  20. #include <asm/sigp.h>
  21. #include <asm/irq.h>
  22. #include <asm/vx-insn.h>
  23. #include <asm/setup.h>
  24. #include <asm/nmi.h>
  25. #include <asm/nospec-insn.h>
  26. __PT_R0 = __PT_GPRS
  27. __PT_R1 = __PT_GPRS + 8
  28. __PT_R2 = __PT_GPRS + 16
  29. __PT_R3 = __PT_GPRS + 24
  30. __PT_R4 = __PT_GPRS + 32
  31. __PT_R5 = __PT_GPRS + 40
  32. __PT_R6 = __PT_GPRS + 48
  33. __PT_R7 = __PT_GPRS + 56
  34. __PT_R8 = __PT_GPRS + 64
  35. __PT_R9 = __PT_GPRS + 72
  36. __PT_R10 = __PT_GPRS + 80
  37. __PT_R11 = __PT_GPRS + 88
  38. __PT_R12 = __PT_GPRS + 96
  39. __PT_R13 = __PT_GPRS + 104
  40. __PT_R14 = __PT_GPRS + 112
  41. __PT_R15 = __PT_GPRS + 120
  42. STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
  43. STACK_SIZE = 1 << STACK_SHIFT
  44. STACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
  45. _TIF_WORK = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
  46. _TIF_UPROBE)
  47. _TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
  48. _TIF_SYSCALL_TRACEPOINT)
  49. _CIF_WORK = (_CIF_MCCK_PENDING | _CIF_ASCE | _CIF_FPU)
  50. _PIF_WORK = (_PIF_PER_TRAP)
  51. #define BASED(name) name-cleanup_critical(%r13)
  52. .macro TRACE_IRQS_ON
  53. #ifdef CONFIG_TRACE_IRQFLAGS
  54. basr %r2,%r0
  55. brasl %r14,trace_hardirqs_on_caller
  56. #endif
  57. .endm
  58. .macro TRACE_IRQS_OFF
  59. #ifdef CONFIG_TRACE_IRQFLAGS
  60. basr %r2,%r0
  61. brasl %r14,trace_hardirqs_off_caller
  62. #endif
  63. .endm
  64. .macro LOCKDEP_SYS_EXIT
  65. #ifdef CONFIG_LOCKDEP
  66. tm __PT_PSW+1(%r11),0x01 # returning to user ?
  67. jz .+10
  68. brasl %r14,lockdep_sys_exit
  69. #endif
  70. .endm
  71. .macro CHECK_STACK stacksize,savearea
  72. #ifdef CONFIG_CHECK_STACK
  73. tml %r15,\stacksize - CONFIG_STACK_GUARD
  74. lghi %r14,\savearea
  75. jz stack_overflow
  76. #endif
  77. .endm
  78. .macro SWITCH_ASYNC savearea,timer
  79. tmhh %r8,0x0001 # interrupting from user ?
  80. jnz 1f
  81. lgr %r14,%r9
  82. slg %r14,BASED(.Lcritical_start)
  83. clg %r14,BASED(.Lcritical_length)
  84. jhe 0f
  85. lghi %r11,\savearea # inside critical section, do cleanup
  86. brasl %r14,cleanup_critical
  87. tmhh %r8,0x0001 # retest problem state after cleanup
  88. jnz 1f
  89. 0: lg %r14,__LC_ASYNC_STACK # are we already on the async stack?
  90. slgr %r14,%r15
  91. srag %r14,%r14,STACK_SHIFT
  92. jnz 2f
  93. CHECK_STACK 1<<STACK_SHIFT,\savearea
  94. aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  95. j 3f
  96. 1: LAST_BREAK %r14
  97. UPDATE_VTIME %r14,%r15,\timer
  98. BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
  99. 2: lg %r15,__LC_ASYNC_STACK # load async stack
  100. 3: la %r11,STACK_FRAME_OVERHEAD(%r15)
  101. .endm
  102. .macro UPDATE_VTIME w1,w2,enter_timer
  103. lg \w1,__LC_EXIT_TIMER
  104. lg \w2,__LC_LAST_UPDATE_TIMER
  105. slg \w1,\enter_timer
  106. slg \w2,__LC_EXIT_TIMER
  107. alg \w1,__LC_USER_TIMER
  108. alg \w2,__LC_SYSTEM_TIMER
  109. stg \w1,__LC_USER_TIMER
  110. stg \w2,__LC_SYSTEM_TIMER
  111. mvc __LC_LAST_UPDATE_TIMER(8),\enter_timer
  112. .endm
  113. .macro LAST_BREAK scratch
  114. srag \scratch,%r10,23
  115. jz .+10
  116. stg %r10,__TI_last_break(%r12)
  117. .endm
  118. .macro REENABLE_IRQS
  119. stg %r8,__LC_RETURN_PSW
  120. ni __LC_RETURN_PSW,0xbf
  121. ssm __LC_RETURN_PSW
  122. .endm
  123. .macro STCK savearea
  124. #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
  125. .insn s,0xb27c0000,\savearea # store clock fast
  126. #else
  127. .insn s,0xb2050000,\savearea # store clock
  128. #endif
  129. .endm
  130. /*
  131. * The TSTMSK macro generates a test-under-mask instruction by
  132. * calculating the memory offset for the specified mask value.
  133. * Mask value can be any constant. The macro shifts the mask
  134. * value to calculate the memory offset for the test-under-mask
  135. * instruction.
  136. */
  137. .macro TSTMSK addr, mask, size=8, bytepos=0
  138. .if (\bytepos < \size) && (\mask >> 8)
  139. .if (\mask & 0xff)
  140. .error "Mask exceeds byte boundary"
  141. .endif
  142. TSTMSK \addr, "(\mask >> 8)", \size, "(\bytepos + 1)"
  143. .exitm
  144. .endif
  145. .ifeq \mask
  146. .error "Mask must not be zero"
  147. .endif
  148. off = \size - \bytepos - 1
  149. tm off+\addr, \mask
  150. .endm
  151. .macro BPOFF
  152. .pushsection .altinstr_replacement, "ax"
  153. 660: .long 0xb2e8c000
  154. .popsection
  155. 661: .long 0x47000000
  156. .pushsection .altinstructions, "a"
  157. .long 661b - .
  158. .long 660b - .
  159. .word 82
  160. .byte 4
  161. .byte 4
  162. .popsection
  163. .endm
  164. .macro BPON
  165. .pushsection .altinstr_replacement, "ax"
  166. 662: .long 0xb2e8d000
  167. .popsection
  168. 663: .long 0x47000000
  169. .pushsection .altinstructions, "a"
  170. .long 663b - .
  171. .long 662b - .
  172. .word 82
  173. .byte 4
  174. .byte 4
  175. .popsection
  176. .endm
  177. .macro BPENTER tif_ptr,tif_mask
  178. .pushsection .altinstr_replacement, "ax"
  179. 662: .word 0xc004, 0x0000, 0x0000 # 6 byte nop
  180. .word 0xc004, 0x0000, 0x0000 # 6 byte nop
  181. .popsection
  182. 664: TSTMSK \tif_ptr,\tif_mask
  183. jz . + 8
  184. .long 0xb2e8d000
  185. .pushsection .altinstructions, "a"
  186. .long 664b - .
  187. .long 662b - .
  188. .word 82
  189. .byte 12
  190. .byte 12
  191. .popsection
  192. .endm
  193. .macro BPEXIT tif_ptr,tif_mask
  194. TSTMSK \tif_ptr,\tif_mask
  195. .pushsection .altinstr_replacement, "ax"
  196. 662: jnz . + 8
  197. .long 0xb2e8d000
  198. .popsection
  199. 664: jz . + 8
  200. .long 0xb2e8c000
  201. .pushsection .altinstructions, "a"
  202. .long 664b - .
  203. .long 662b - .
  204. .word 82
  205. .byte 8
  206. .byte 8
  207. .popsection
  208. .endm
  209. GEN_BR_THUNK %r9
  210. GEN_BR_THUNK %r14
  211. GEN_BR_THUNK %r14,%r11
  212. .section .kprobes.text, "ax"
  213. ENTRY(__bpon)
  214. .globl __bpon
  215. BPON
  216. BR_EX %r14
  217. /*
  218. * Scheduler resume function, called by switch_to
  219. * gpr2 = (task_struct *) prev
  220. * gpr3 = (task_struct *) next
  221. * Returns:
  222. * gpr2 = prev
  223. */
  224. ENTRY(__switch_to)
  225. stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
  226. lgr %r1,%r2
  227. aghi %r1,__TASK_thread # thread_struct of prev task
  228. lg %r4,__TASK_thread_info(%r2) # get thread_info of prev
  229. lg %r5,__TASK_thread_info(%r3) # get thread_info of next
  230. stg %r15,__THREAD_ksp(%r1) # store kernel stack of prev
  231. lgr %r1,%r3
  232. aghi %r1,__TASK_thread # thread_struct of next task
  233. lgr %r15,%r5
  234. aghi %r15,STACK_INIT # end of kernel stack of next
  235. stg %r3,__LC_CURRENT # store task struct of next
  236. stg %r5,__LC_THREAD_INFO # store thread info of next
  237. stg %r15,__LC_KERNEL_STACK # store end of kernel stack
  238. lg %r15,__THREAD_ksp(%r1) # load kernel stack of next
  239. lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
  240. mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next
  241. lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
  242. TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
  243. jz 0f
  244. .insn s,0xb2800000,__LC_LPP # set program parameter
  245. 0: BR_EX %r14
  246. .L__critical_start:
  247. #if IS_ENABLED(CONFIG_KVM)
  248. /*
  249. * sie64a calling convention:
  250. * %r2 pointer to sie control block
  251. * %r3 guest register save area
  252. */
  253. ENTRY(sie64a)
  254. stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
  255. lg %r12,__LC_CURRENT
  256. stg %r2,__SF_EMPTY(%r15) # save control block pointer
  257. stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
  258. xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # reason code = 0
  259. mvc __SF_EMPTY+24(8,%r15),__TI_flags(%r12) # copy thread flags
  260. TSTMSK __LC_CPU_FLAGS,_CIF_FPU # load guest fp/vx registers ?
  261. jno .Lsie_load_guest_gprs
  262. brasl %r14,load_fpu_regs # load guest fp/vx regs
  263. .Lsie_load_guest_gprs:
  264. lmg %r0,%r13,0(%r3) # load guest gprs 0-13
  265. lg %r14,__LC_GMAP # get gmap pointer
  266. ltgr %r14,%r14
  267. jz .Lsie_gmap
  268. lctlg %c1,%c1,__GMAP_ASCE(%r14) # load primary asce
  269. .Lsie_gmap:
  270. lg %r14,__SF_EMPTY(%r15) # get control block pointer
  271. oi __SIE_PROG0C+3(%r14),1 # we are going into SIE now
  272. tm __SIE_PROG20+3(%r14),3 # last exit...
  273. jnz .Lsie_skip
  274. TSTMSK __LC_CPU_FLAGS,_CIF_FPU
  275. jo .Lsie_skip # exit if fp/vx regs changed
  276. BPEXIT __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
  277. sie 0(%r14)
  278. .Lsie_exit:
  279. BPOFF
  280. BPENTER __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
  281. .Lsie_skip:
  282. ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
  283. lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
  284. .Lsie_done:
  285. # some program checks are suppressing. C code (e.g. do_protection_exception)
  286. # will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There
  287. # are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable.
  288. # Other instructions between sie64a and .Lsie_done should not cause program
  289. # interrupts. So lets use 3 nops as a landing pad for all possible rewinds.
  290. # See also .Lcleanup_sie
  291. .Lrewind_pad6:
  292. nopr 7
  293. .Lrewind_pad4:
  294. nopr 7
  295. .Lrewind_pad2:
  296. nopr 7
  297. .globl sie_exit
  298. sie_exit:
  299. lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
  300. stmg %r0,%r13,0(%r14) # save guest gprs 0-13
  301. xgr %r0,%r0 # clear guest registers to
  302. xgr %r1,%r1 # prevent speculative use
  303. xgr %r2,%r2
  304. xgr %r3,%r3
  305. xgr %r4,%r4
  306. xgr %r5,%r5
  307. lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
  308. lg %r2,__SF_EMPTY+16(%r15) # return exit reason code
  309. BR_EX %r14
  310. .Lsie_fault:
  311. lghi %r14,-EFAULT
  312. stg %r14,__SF_EMPTY+16(%r15) # set exit reason code
  313. j sie_exit
  314. EX_TABLE(.Lrewind_pad6,.Lsie_fault)
  315. EX_TABLE(.Lrewind_pad4,.Lsie_fault)
  316. EX_TABLE(.Lrewind_pad2,.Lsie_fault)
  317. EX_TABLE(sie_exit,.Lsie_fault)
  318. #endif
  319. /*
  320. * SVC interrupt handler routine. System calls are synchronous events and
  321. * are executed with interrupts enabled.
  322. */
  323. ENTRY(system_call)
  324. stpt __LC_SYNC_ENTER_TIMER
  325. .Lsysc_stmg:
  326. stmg %r8,%r15,__LC_SAVE_AREA_SYNC
  327. BPOFF
  328. lg %r10,__LC_LAST_BREAK
  329. lg %r12,__LC_THREAD_INFO
  330. lghi %r14,_PIF_SYSCALL
  331. .Lsysc_per:
  332. lg %r15,__LC_KERNEL_STACK
  333. la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
  334. LAST_BREAK %r13
  335. .Lsysc_vtime:
  336. UPDATE_VTIME %r10,%r13,__LC_SYNC_ENTER_TIMER
  337. BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
  338. stmg %r0,%r7,__PT_R0(%r11)
  339. mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
  340. mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
  341. mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
  342. stg %r14,__PT_FLAGS(%r11)
  343. .Lsysc_do_svc:
  344. # clear user controlled register to prevent speculative use
  345. xgr %r0,%r0
  346. lg %r10,__TI_sysc_table(%r12) # address of system call table
  347. llgh %r8,__PT_INT_CODE+2(%r11)
  348. slag %r8,%r8,2 # shift and test for svc 0
  349. jnz .Lsysc_nr_ok
  350. # svc 0: system call number in %r1
  351. llgfr %r1,%r1 # clear high word in r1
  352. cghi %r1,NR_syscalls
  353. jnl .Lsysc_nr_ok
  354. sth %r1,__PT_INT_CODE+2(%r11)
  355. slag %r8,%r1,2
  356. .Lsysc_nr_ok:
  357. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  358. stg %r2,__PT_ORIG_GPR2(%r11)
  359. stg %r7,STACK_FRAME_OVERHEAD(%r15)
  360. lgf %r9,0(%r8,%r10) # get system call add.
  361. TSTMSK __TI_flags(%r12),_TIF_TRACE
  362. jnz .Lsysc_tracesys
  363. BASR_EX %r14,%r9 # call sys_xxxx
  364. stg %r2,__PT_R2(%r11) # store return value
  365. .Lsysc_return:
  366. LOCKDEP_SYS_EXIT
  367. .Lsysc_tif:
  368. TSTMSK __PT_FLAGS(%r11),_PIF_WORK
  369. jnz .Lsysc_work
  370. TSTMSK __TI_flags(%r12),_TIF_WORK
  371. jnz .Lsysc_work # check for work
  372. TSTMSK __LC_CPU_FLAGS,_CIF_WORK
  373. jnz .Lsysc_work
  374. BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
  375. .Lsysc_restore:
  376. lg %r14,__LC_VDSO_PER_CPU
  377. lmg %r0,%r10,__PT_R0(%r11)
  378. mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
  379. .Lsysc_exit_timer:
  380. stpt __LC_EXIT_TIMER
  381. mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
  382. lmg %r11,%r15,__PT_R11(%r11)
  383. lpswe __LC_RETURN_PSW
  384. .Lsysc_done:
  385. #
  386. # One of the work bits is on. Find out which one.
  387. #
  388. .Lsysc_work:
  389. TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
  390. jo .Lsysc_mcck_pending
  391. TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
  392. jo .Lsysc_reschedule
  393. #ifdef CONFIG_UPROBES
  394. TSTMSK __TI_flags(%r12),_TIF_UPROBE
  395. jo .Lsysc_uprobe_notify
  396. #endif
  397. TSTMSK __PT_FLAGS(%r11),_PIF_PER_TRAP
  398. jo .Lsysc_singlestep
  399. TSTMSK __TI_flags(%r12),_TIF_SIGPENDING
  400. jo .Lsysc_sigpending
  401. TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME
  402. jo .Lsysc_notify_resume
  403. TSTMSK __LC_CPU_FLAGS,_CIF_FPU
  404. jo .Lsysc_vxrs
  405. TSTMSK __LC_CPU_FLAGS,_CIF_ASCE
  406. jo .Lsysc_uaccess
  407. j .Lsysc_return # beware of critical section cleanup
  408. #
  409. # _TIF_NEED_RESCHED is set, call schedule
  410. #
  411. .Lsysc_reschedule:
  412. larl %r14,.Lsysc_return
  413. jg schedule
  414. #
  415. # _CIF_MCCK_PENDING is set, call handler
  416. #
  417. .Lsysc_mcck_pending:
  418. larl %r14,.Lsysc_return
  419. jg s390_handle_mcck # TIF bit will be cleared by handler
  420. #
  421. # _CIF_ASCE is set, load user space asce
  422. #
  423. .Lsysc_uaccess:
  424. ni __LC_CPU_FLAGS+7,255-_CIF_ASCE
  425. lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
  426. j .Lsysc_return
  427. #
  428. # CIF_FPU is set, restore floating-point controls and floating-point registers.
  429. #
  430. .Lsysc_vxrs:
  431. larl %r14,.Lsysc_return
  432. jg load_fpu_regs
  433. #
  434. # _TIF_SIGPENDING is set, call do_signal
  435. #
  436. .Lsysc_sigpending:
  437. lgr %r2,%r11 # pass pointer to pt_regs
  438. brasl %r14,do_signal
  439. TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL
  440. jno .Lsysc_return
  441. lmg %r2,%r7,__PT_R2(%r11) # load svc arguments
  442. lg %r10,__TI_sysc_table(%r12) # address of system call table
  443. lghi %r8,0 # svc 0 returns -ENOSYS
  444. llgh %r1,__PT_INT_CODE+2(%r11) # load new svc number
  445. cghi %r1,NR_syscalls
  446. jnl .Lsysc_nr_ok # invalid svc number -> do svc 0
  447. slag %r8,%r1,2
  448. j .Lsysc_nr_ok # restart svc
  449. #
  450. # _TIF_NOTIFY_RESUME is set, call do_notify_resume
  451. #
  452. .Lsysc_notify_resume:
  453. lgr %r2,%r11 # pass pointer to pt_regs
  454. larl %r14,.Lsysc_return
  455. jg do_notify_resume
  456. #
  457. # _TIF_UPROBE is set, call uprobe_notify_resume
  458. #
  459. #ifdef CONFIG_UPROBES
  460. .Lsysc_uprobe_notify:
  461. lgr %r2,%r11 # pass pointer to pt_regs
  462. larl %r14,.Lsysc_return
  463. jg uprobe_notify_resume
  464. #endif
  465. #
  466. # _PIF_PER_TRAP is set, call do_per_trap
  467. #
  468. .Lsysc_singlestep:
  469. ni __PT_FLAGS+7(%r11),255-_PIF_PER_TRAP
  470. lgr %r2,%r11 # pass pointer to pt_regs
  471. larl %r14,.Lsysc_return
  472. jg do_per_trap
  473. #
  474. # call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
  475. # and after the system call
  476. #
  477. .Lsysc_tracesys:
  478. lgr %r2,%r11 # pass pointer to pt_regs
  479. la %r3,0
  480. llgh %r0,__PT_INT_CODE+2(%r11)
  481. stg %r0,__PT_R2(%r11)
  482. brasl %r14,do_syscall_trace_enter
  483. lghi %r0,NR_syscalls
  484. clgr %r0,%r2
  485. jnh .Lsysc_tracenogo
  486. sllg %r8,%r2,2
  487. lgf %r9,0(%r8,%r10)
  488. .Lsysc_tracego:
  489. lmg %r3,%r7,__PT_R3(%r11)
  490. stg %r7,STACK_FRAME_OVERHEAD(%r15)
  491. lg %r2,__PT_ORIG_GPR2(%r11)
  492. BASR_EX %r14,%r9 # call sys_xxx
  493. stg %r2,__PT_R2(%r11) # store return value
  494. .Lsysc_tracenogo:
  495. TSTMSK __TI_flags(%r12),_TIF_TRACE
  496. jz .Lsysc_return
  497. lgr %r2,%r11 # pass pointer to pt_regs
  498. larl %r14,.Lsysc_return
  499. jg do_syscall_trace_exit
  500. #
  501. # a new process exits the kernel with ret_from_fork
  502. #
  503. ENTRY(ret_from_fork)
  504. la %r11,STACK_FRAME_OVERHEAD(%r15)
  505. lg %r12,__LC_THREAD_INFO
  506. brasl %r14,schedule_tail
  507. TRACE_IRQS_ON
  508. ssm __LC_SVC_NEW_PSW # reenable interrupts
  509. tm __PT_PSW+1(%r11),0x01 # forking a kernel thread ?
  510. jne .Lsysc_tracenogo
  511. # it's a kernel thread
  512. lmg %r9,%r10,__PT_R9(%r11) # load gprs
  513. ENTRY(kernel_thread_starter)
  514. la %r2,0(%r10)
  515. BASR_EX %r14,%r9
  516. j .Lsysc_tracenogo
  517. /*
  518. * Program check handler routine
  519. */
  520. ENTRY(pgm_check_handler)
  521. stpt __LC_SYNC_ENTER_TIMER
  522. BPOFF
  523. stmg %r8,%r15,__LC_SAVE_AREA_SYNC
  524. lg %r10,__LC_LAST_BREAK
  525. lg %r12,__LC_THREAD_INFO
  526. larl %r13,cleanup_critical
  527. lmg %r8,%r9,__LC_PGM_OLD_PSW
  528. tmhh %r8,0x0001 # test problem state bit
  529. jnz 2f # -> fault in user space
  530. #if IS_ENABLED(CONFIG_KVM)
  531. # cleanup critical section for sie64a
  532. lgr %r14,%r9
  533. slg %r14,BASED(.Lsie_critical_start)
  534. clg %r14,BASED(.Lsie_critical_length)
  535. jhe 0f
  536. brasl %r14,.Lcleanup_sie
  537. #endif
  538. 0: tmhh %r8,0x4000 # PER bit set in old PSW ?
  539. jnz 1f # -> enabled, can't be a double fault
  540. tm __LC_PGM_ILC+3,0x80 # check for per exception
  541. jnz .Lpgm_svcper # -> single stepped svc
  542. 1: CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
  543. aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  544. j 3f
  545. 2: LAST_BREAK %r14
  546. UPDATE_VTIME %r14,%r15,__LC_SYNC_ENTER_TIMER
  547. BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
  548. lg %r15,__LC_KERNEL_STACK
  549. lg %r14,__TI_task(%r12)
  550. aghi %r14,__TASK_thread # pointer to thread_struct
  551. lghi %r13,__LC_PGM_TDB
  552. tm __LC_PGM_ILC+2,0x02 # check for transaction abort
  553. jz 3f
  554. mvc __THREAD_trap_tdb(256,%r14),0(%r13)
  555. 3: la %r11,STACK_FRAME_OVERHEAD(%r15)
  556. stmg %r0,%r7,__PT_R0(%r11)
  557. # clear user controlled registers to prevent speculative use
  558. xgr %r0,%r0
  559. xgr %r1,%r1
  560. xgr %r2,%r2
  561. xgr %r3,%r3
  562. xgr %r4,%r4
  563. xgr %r5,%r5
  564. xgr %r6,%r6
  565. xgr %r7,%r7
  566. mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
  567. stmg %r8,%r9,__PT_PSW(%r11)
  568. mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
  569. mvc __PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
  570. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  571. stg %r10,__PT_ARGS(%r11)
  572. tm __LC_PGM_ILC+3,0x80 # check for per exception
  573. jz 4f
  574. tmhh %r8,0x0001 # kernel per event ?
  575. jz .Lpgm_kprobe
  576. oi __PT_FLAGS+7(%r11),_PIF_PER_TRAP
  577. mvc __THREAD_per_address(8,%r14),__LC_PER_ADDRESS
  578. mvc __THREAD_per_cause(2,%r14),__LC_PER_CODE
  579. mvc __THREAD_per_paid(1,%r14),__LC_PER_ACCESS_ID
  580. 4: REENABLE_IRQS
  581. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  582. larl %r1,pgm_check_table
  583. llgh %r10,__PT_INT_CODE+2(%r11)
  584. nill %r10,0x007f
  585. sll %r10,2
  586. je .Lpgm_return
  587. lgf %r9,0(%r10,%r1) # load address of handler routine
  588. lgr %r2,%r11 # pass pointer to pt_regs
  589. BASR_EX %r14,%r9 # branch to interrupt-handler
  590. .Lpgm_return:
  591. LOCKDEP_SYS_EXIT
  592. tm __PT_PSW+1(%r11),0x01 # returning to user ?
  593. jno .Lsysc_restore
  594. j .Lsysc_tif
  595. #
  596. # PER event in supervisor state, must be kprobes
  597. #
  598. .Lpgm_kprobe:
  599. REENABLE_IRQS
  600. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  601. lgr %r2,%r11 # pass pointer to pt_regs
  602. brasl %r14,do_per_trap
  603. j .Lpgm_return
  604. #
  605. # single stepped system call
  606. #
  607. .Lpgm_svcper:
  608. mvc __LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
  609. larl %r14,.Lsysc_per
  610. stg %r14,__LC_RETURN_PSW+8
  611. lghi %r14,_PIF_SYSCALL | _PIF_PER_TRAP
  612. lpswe __LC_RETURN_PSW # branch to .Lsysc_per and enable irqs
  613. /*
  614. * IO interrupt handler routine
  615. */
  616. ENTRY(io_int_handler)
  617. STCK __LC_INT_CLOCK
  618. stpt __LC_ASYNC_ENTER_TIMER
  619. BPOFF
  620. stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
  621. lg %r10,__LC_LAST_BREAK
  622. lg %r12,__LC_THREAD_INFO
  623. larl %r13,cleanup_critical
  624. lmg %r8,%r9,__LC_IO_OLD_PSW
  625. SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
  626. stmg %r0,%r7,__PT_R0(%r11)
  627. # clear user controlled registers to prevent speculative use
  628. xgr %r0,%r0
  629. xgr %r1,%r1
  630. xgr %r2,%r2
  631. xgr %r3,%r3
  632. xgr %r4,%r4
  633. xgr %r5,%r5
  634. xgr %r6,%r6
  635. xgr %r7,%r7
  636. xgr %r10,%r10
  637. mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
  638. stmg %r8,%r9,__PT_PSW(%r11)
  639. mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
  640. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  641. TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ
  642. jo .Lio_restore
  643. TRACE_IRQS_OFF
  644. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  645. .Lio_loop:
  646. lgr %r2,%r11 # pass pointer to pt_regs
  647. lghi %r3,IO_INTERRUPT
  648. tm __PT_INT_CODE+8(%r11),0x80 # adapter interrupt ?
  649. jz .Lio_call
  650. lghi %r3,THIN_INTERRUPT
  651. .Lio_call:
  652. brasl %r14,do_IRQ
  653. TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPAR
  654. jz .Lio_return
  655. tpi 0
  656. jz .Lio_return
  657. mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
  658. j .Lio_loop
  659. .Lio_return:
  660. LOCKDEP_SYS_EXIT
  661. TRACE_IRQS_ON
  662. .Lio_tif:
  663. TSTMSK __TI_flags(%r12),_TIF_WORK
  664. jnz .Lio_work # there is work to do (signals etc.)
  665. TSTMSK __LC_CPU_FLAGS,_CIF_WORK
  666. jnz .Lio_work
  667. .Lio_restore:
  668. lg %r14,__LC_VDSO_PER_CPU
  669. lmg %r0,%r10,__PT_R0(%r11)
  670. mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
  671. tm __PT_PSW+1(%r11),0x01 # returning to user ?
  672. jno .Lio_exit_kernel
  673. BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
  674. .Lio_exit_timer:
  675. stpt __LC_EXIT_TIMER
  676. mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
  677. .Lio_exit_kernel:
  678. lmg %r11,%r15,__PT_R11(%r11)
  679. lpswe __LC_RETURN_PSW
  680. .Lio_done:
  681. #
  682. # There is work todo, find out in which context we have been interrupted:
  683. # 1) if we return to user space we can do all _TIF_WORK work
  684. # 2) if we return to kernel code and kvm is enabled check if we need to
  685. # modify the psw to leave SIE
  686. # 3) if we return to kernel code and preemptive scheduling is enabled check
  687. # the preemption counter and if it is zero call preempt_schedule_irq
  688. # Before any work can be done, a switch to the kernel stack is required.
  689. #
  690. .Lio_work:
  691. tm __PT_PSW+1(%r11),0x01 # returning to user ?
  692. jo .Lio_work_user # yes -> do resched & signal
  693. #ifdef CONFIG_PREEMPT
  694. # check for preemptive scheduling
  695. icm %r0,15,__TI_precount(%r12)
  696. jnz .Lio_restore # preemption is disabled
  697. TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
  698. jno .Lio_restore
  699. # switch to kernel stack
  700. lg %r1,__PT_R15(%r11)
  701. aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  702. mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
  703. xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
  704. la %r11,STACK_FRAME_OVERHEAD(%r1)
  705. lgr %r15,%r1
  706. # TRACE_IRQS_ON already done at .Lio_return, call
  707. # TRACE_IRQS_OFF to keep things symmetrical
  708. TRACE_IRQS_OFF
  709. brasl %r14,preempt_schedule_irq
  710. j .Lio_return
  711. #else
  712. j .Lio_restore
  713. #endif
  714. #
  715. # Need to do work before returning to userspace, switch to kernel stack
  716. #
  717. .Lio_work_user:
  718. lg %r1,__LC_KERNEL_STACK
  719. mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
  720. xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
  721. la %r11,STACK_FRAME_OVERHEAD(%r1)
  722. lgr %r15,%r1
  723. #
  724. # One of the work bits is on. Find out which one.
  725. #
  726. .Lio_work_tif:
  727. TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
  728. jo .Lio_mcck_pending
  729. TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
  730. jo .Lio_reschedule
  731. TSTMSK __TI_flags(%r12),_TIF_SIGPENDING
  732. jo .Lio_sigpending
  733. TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME
  734. jo .Lio_notify_resume
  735. TSTMSK __LC_CPU_FLAGS,_CIF_FPU
  736. jo .Lio_vxrs
  737. TSTMSK __LC_CPU_FLAGS,_CIF_ASCE
  738. jo .Lio_uaccess
  739. j .Lio_return # beware of critical section cleanup
  740. #
  741. # _CIF_MCCK_PENDING is set, call handler
  742. #
  743. .Lio_mcck_pending:
  744. # TRACE_IRQS_ON already done at .Lio_return
  745. brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
  746. TRACE_IRQS_OFF
  747. j .Lio_return
  748. #
  749. # _CIF_ASCE is set, load user space asce
  750. #
  751. .Lio_uaccess:
  752. ni __LC_CPU_FLAGS+7,255-_CIF_ASCE
  753. lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
  754. j .Lio_return
  755. #
  756. # CIF_FPU is set, restore floating-point controls and floating-point registers.
  757. #
  758. .Lio_vxrs:
  759. larl %r14,.Lio_return
  760. jg load_fpu_regs
  761. #
  762. # _TIF_NEED_RESCHED is set, call schedule
  763. #
  764. .Lio_reschedule:
  765. # TRACE_IRQS_ON already done at .Lio_return
  766. ssm __LC_SVC_NEW_PSW # reenable interrupts
  767. brasl %r14,schedule # call scheduler
  768. ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
  769. TRACE_IRQS_OFF
  770. j .Lio_return
  771. #
  772. # _TIF_SIGPENDING or is set, call do_signal
  773. #
  774. .Lio_sigpending:
  775. # TRACE_IRQS_ON already done at .Lio_return
  776. ssm __LC_SVC_NEW_PSW # reenable interrupts
  777. lgr %r2,%r11 # pass pointer to pt_regs
  778. brasl %r14,do_signal
  779. ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
  780. TRACE_IRQS_OFF
  781. j .Lio_return
  782. #
  783. # _TIF_NOTIFY_RESUME or is set, call do_notify_resume
  784. #
  785. .Lio_notify_resume:
  786. # TRACE_IRQS_ON already done at .Lio_return
  787. ssm __LC_SVC_NEW_PSW # reenable interrupts
  788. lgr %r2,%r11 # pass pointer to pt_regs
  789. brasl %r14,do_notify_resume
  790. ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
  791. TRACE_IRQS_OFF
  792. j .Lio_return
  793. /*
  794. * External interrupt handler routine
  795. */
  796. ENTRY(ext_int_handler)
  797. STCK __LC_INT_CLOCK
  798. stpt __LC_ASYNC_ENTER_TIMER
  799. BPOFF
  800. stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
  801. lg %r10,__LC_LAST_BREAK
  802. lg %r12,__LC_THREAD_INFO
  803. larl %r13,cleanup_critical
  804. lmg %r8,%r9,__LC_EXT_OLD_PSW
  805. SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
  806. stmg %r0,%r7,__PT_R0(%r11)
  807. # clear user controlled registers to prevent speculative use
  808. xgr %r0,%r0
  809. xgr %r1,%r1
  810. xgr %r2,%r2
  811. xgr %r3,%r3
  812. xgr %r4,%r4
  813. xgr %r5,%r5
  814. xgr %r6,%r6
  815. xgr %r7,%r7
  816. xgr %r10,%r10
  817. mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
  818. stmg %r8,%r9,__PT_PSW(%r11)
  819. lghi %r1,__LC_EXT_PARAMS2
  820. mvc __PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
  821. mvc __PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
  822. mvc __PT_INT_PARM_LONG(8,%r11),0(%r1)
  823. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  824. TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ
  825. jo .Lio_restore
  826. TRACE_IRQS_OFF
  827. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  828. lgr %r2,%r11 # pass pointer to pt_regs
  829. lghi %r3,EXT_INTERRUPT
  830. brasl %r14,do_IRQ
  831. j .Lio_return
  832. /*
  833. * Load idle PSW. The second "half" of this function is in .Lcleanup_idle.
  834. */
  835. ENTRY(psw_idle)
  836. stg %r3,__SF_EMPTY(%r15)
  837. larl %r1,.Lpsw_idle_lpsw+4
  838. stg %r1,__SF_EMPTY+8(%r15)
  839. #ifdef CONFIG_SMP
  840. larl %r1,smp_cpu_mtid
  841. llgf %r1,0(%r1)
  842. ltgr %r1,%r1
  843. jz .Lpsw_idle_stcctm
  844. .insn rsy,0xeb0000000017,%r1,5,__SF_EMPTY+16(%r15)
  845. .Lpsw_idle_stcctm:
  846. #endif
  847. BPON
  848. STCK __CLOCK_IDLE_ENTER(%r2)
  849. stpt __TIMER_IDLE_ENTER(%r2)
  850. .Lpsw_idle_lpsw:
  851. lpswe __SF_EMPTY(%r15)
  852. BR_EX %r14
  853. .Lpsw_idle_end:
  854. /*
  855. * Store floating-point controls and floating-point or vector register
  856. * depending whether the vector facility is available. A critical section
  857. * cleanup assures that the registers are stored even if interrupted for
  858. * some other work. The CIF_FPU flag is set to trigger a lazy restore
  859. * of the register contents at return from io or a system call.
  860. */
  861. ENTRY(save_fpu_regs)
  862. lg %r2,__LC_CURRENT
  863. aghi %r2,__TASK_thread
  864. TSTMSK __LC_CPU_FLAGS,_CIF_FPU
  865. jo .Lsave_fpu_regs_exit
  866. stfpc __THREAD_FPU_fpc(%r2)
  867. .Lsave_fpu_regs_fpc_end:
  868. lg %r3,__THREAD_FPU_regs(%r2)
  869. TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
  870. jz .Lsave_fpu_regs_fp # no -> store FP regs
  871. .Lsave_fpu_regs_vx_low:
  872. VSTM %v0,%v15,0,%r3 # vstm 0,15,0(3)
  873. .Lsave_fpu_regs_vx_high:
  874. VSTM %v16,%v31,256,%r3 # vstm 16,31,256(3)
  875. j .Lsave_fpu_regs_done # -> set CIF_FPU flag
  876. .Lsave_fpu_regs_fp:
  877. std 0,0(%r3)
  878. std 1,8(%r3)
  879. std 2,16(%r3)
  880. std 3,24(%r3)
  881. std 4,32(%r3)
  882. std 5,40(%r3)
  883. std 6,48(%r3)
  884. std 7,56(%r3)
  885. std 8,64(%r3)
  886. std 9,72(%r3)
  887. std 10,80(%r3)
  888. std 11,88(%r3)
  889. std 12,96(%r3)
  890. std 13,104(%r3)
  891. std 14,112(%r3)
  892. std 15,120(%r3)
  893. .Lsave_fpu_regs_done:
  894. oi __LC_CPU_FLAGS+7,_CIF_FPU
  895. .Lsave_fpu_regs_exit:
  896. BR_EX %r14
  897. .Lsave_fpu_regs_end:
  898. /*
  899. * Load floating-point controls and floating-point or vector registers.
  900. * A critical section cleanup assures that the register contents are
  901. * loaded even if interrupted for some other work.
  902. *
  903. * There are special calling conventions to fit into sysc and io return work:
  904. * %r15: <kernel stack>
  905. * The function requires:
  906. * %r4
  907. */
  908. load_fpu_regs:
  909. lg %r4,__LC_CURRENT
  910. aghi %r4,__TASK_thread
  911. TSTMSK __LC_CPU_FLAGS,_CIF_FPU
  912. jno .Lload_fpu_regs_exit
  913. lfpc __THREAD_FPU_fpc(%r4)
  914. TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
  915. lg %r4,__THREAD_FPU_regs(%r4) # %r4 <- reg save area
  916. jz .Lload_fpu_regs_fp # -> no VX, load FP regs
  917. .Lload_fpu_regs_vx:
  918. VLM %v0,%v15,0,%r4
  919. .Lload_fpu_regs_vx_high:
  920. VLM %v16,%v31,256,%r4
  921. j .Lload_fpu_regs_done
  922. .Lload_fpu_regs_fp:
  923. ld 0,0(%r4)
  924. ld 1,8(%r4)
  925. ld 2,16(%r4)
  926. ld 3,24(%r4)
  927. ld 4,32(%r4)
  928. ld 5,40(%r4)
  929. ld 6,48(%r4)
  930. ld 7,56(%r4)
  931. ld 8,64(%r4)
  932. ld 9,72(%r4)
  933. ld 10,80(%r4)
  934. ld 11,88(%r4)
  935. ld 12,96(%r4)
  936. ld 13,104(%r4)
  937. ld 14,112(%r4)
  938. ld 15,120(%r4)
  939. .Lload_fpu_regs_done:
  940. ni __LC_CPU_FLAGS+7,255-_CIF_FPU
  941. .Lload_fpu_regs_exit:
  942. BR_EX %r14
  943. .Lload_fpu_regs_end:
  944. .L__critical_end:
  945. /*
  946. * Machine check handler routines
  947. */
  948. ENTRY(mcck_int_handler)
  949. STCK __LC_MCCK_CLOCK
  950. BPOFF
  951. la %r1,4095 # revalidate r1
  952. spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
  953. lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
  954. lg %r10,__LC_LAST_BREAK
  955. lg %r12,__LC_THREAD_INFO
  956. larl %r13,cleanup_critical
  957. lmg %r8,%r9,__LC_MCK_OLD_PSW
  958. TSTMSK __LC_MCCK_CODE,MCCK_CODE_SYSTEM_DAMAGE
  959. jo .Lmcck_panic # yes -> rest of mcck code invalid
  960. lghi %r14,__LC_CPU_TIMER_SAVE_AREA
  961. mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
  962. TSTMSK __LC_MCCK_CODE,MCCK_CODE_CPU_TIMER_VALID
  963. jo 3f
  964. la %r14,__LC_SYNC_ENTER_TIMER
  965. clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
  966. jl 0f
  967. la %r14,__LC_ASYNC_ENTER_TIMER
  968. 0: clc 0(8,%r14),__LC_EXIT_TIMER
  969. jl 1f
  970. la %r14,__LC_EXIT_TIMER
  971. 1: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
  972. jl 2f
  973. la %r14,__LC_LAST_UPDATE_TIMER
  974. 2: spt 0(%r14)
  975. mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
  976. 3: TSTMSK __LC_MCCK_CODE,(MCCK_CODE_PSW_MWP_VALID|MCCK_CODE_PSW_IA_VALID)
  977. jno .Lmcck_panic # no -> skip cleanup critical
  978. SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_MCCK_ENTER_TIMER
  979. .Lmcck_skip:
  980. lghi %r14,__LC_GPREGS_SAVE_AREA+64
  981. stmg %r0,%r7,__PT_R0(%r11)
  982. # clear user controlled registers to prevent speculative use
  983. xgr %r0,%r0
  984. xgr %r1,%r1
  985. xgr %r2,%r2
  986. xgr %r3,%r3
  987. xgr %r4,%r4
  988. xgr %r5,%r5
  989. xgr %r6,%r6
  990. xgr %r7,%r7
  991. xgr %r10,%r10
  992. mvc __PT_R8(64,%r11),0(%r14)
  993. stmg %r8,%r9,__PT_PSW(%r11)
  994. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  995. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  996. lgr %r2,%r11 # pass pointer to pt_regs
  997. brasl %r14,s390_do_machine_check
  998. tm __PT_PSW+1(%r11),0x01 # returning to user ?
  999. jno .Lmcck_return
  1000. lg %r1,__LC_KERNEL_STACK # switch to kernel stack
  1001. mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
  1002. xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
  1003. la %r11,STACK_FRAME_OVERHEAD(%r1)
  1004. lgr %r15,%r1
  1005. ssm __LC_PGM_NEW_PSW # turn dat on, keep irqs off
  1006. TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
  1007. jno .Lmcck_return
  1008. TRACE_IRQS_OFF
  1009. brasl %r14,s390_handle_mcck
  1010. TRACE_IRQS_ON
  1011. .Lmcck_return:
  1012. lg %r14,__LC_VDSO_PER_CPU
  1013. lmg %r0,%r10,__PT_R0(%r11)
  1014. mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
  1015. tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
  1016. jno 0f
  1017. BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
  1018. stpt __LC_EXIT_TIMER
  1019. mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
  1020. 0: lmg %r11,%r15,__PT_R11(%r11)
  1021. lpswe __LC_RETURN_MCCK_PSW
  1022. .Lmcck_panic:
  1023. lg %r15,__LC_PANIC_STACK
  1024. aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  1025. j .Lmcck_skip
  1026. #
  1027. # PSW restart interrupt handler
  1028. #
  1029. ENTRY(restart_int_handler)
  1030. TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
  1031. jz 0f
  1032. .insn s,0xb2800000,__LC_LPP
  1033. 0: stg %r15,__LC_SAVE_AREA_RESTART
  1034. lg %r15,__LC_RESTART_STACK
  1035. aghi %r15,-__PT_SIZE # create pt_regs on stack
  1036. xc 0(__PT_SIZE,%r15),0(%r15)
  1037. stmg %r0,%r14,__PT_R0(%r15)
  1038. mvc __PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
  1039. mvc __PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
  1040. aghi %r15,-STACK_FRAME_OVERHEAD # create stack frame on stack
  1041. xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
  1042. lg %r1,__LC_RESTART_FN # load fn, parm & source cpu
  1043. lg %r2,__LC_RESTART_DATA
  1044. lg %r3,__LC_RESTART_SOURCE
  1045. ltgr %r3,%r3 # test source cpu address
  1046. jm 1f # negative -> skip source stop
  1047. 0: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
  1048. brc 10,0b # wait for status stored
  1049. 1: basr %r14,%r1 # call function
  1050. stap __SF_EMPTY(%r15) # store cpu address
  1051. llgh %r3,__SF_EMPTY(%r15)
  1052. 2: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
  1053. brc 2,2b
  1054. 3: j 3b
  1055. .section .kprobes.text, "ax"
  1056. #ifdef CONFIG_CHECK_STACK
  1057. /*
  1058. * The synchronous or the asynchronous stack overflowed. We are dead.
  1059. * No need to properly save the registers, we are going to panic anyway.
  1060. * Setup a pt_regs so that show_trace can provide a good call trace.
  1061. */
  1062. stack_overflow:
  1063. lg %r15,__LC_PANIC_STACK # change to panic stack
  1064. la %r11,STACK_FRAME_OVERHEAD(%r15)
  1065. stmg %r0,%r7,__PT_R0(%r11)
  1066. stmg %r8,%r9,__PT_PSW(%r11)
  1067. mvc __PT_R8(64,%r11),0(%r14)
  1068. stg %r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
  1069. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  1070. lgr %r2,%r11 # pass pointer to pt_regs
  1071. jg kernel_stack_overflow
  1072. #endif
  1073. cleanup_critical:
  1074. #if IS_ENABLED(CONFIG_KVM)
  1075. clg %r9,BASED(.Lcleanup_table_sie) # .Lsie_gmap
  1076. jl 0f
  1077. clg %r9,BASED(.Lcleanup_table_sie+8)# .Lsie_done
  1078. jl .Lcleanup_sie
  1079. #endif
  1080. clg %r9,BASED(.Lcleanup_table) # system_call
  1081. jl 0f
  1082. clg %r9,BASED(.Lcleanup_table+8) # .Lsysc_do_svc
  1083. jl .Lcleanup_system_call
  1084. clg %r9,BASED(.Lcleanup_table+16) # .Lsysc_tif
  1085. jl 0f
  1086. clg %r9,BASED(.Lcleanup_table+24) # .Lsysc_restore
  1087. jl .Lcleanup_sysc_tif
  1088. clg %r9,BASED(.Lcleanup_table+32) # .Lsysc_done
  1089. jl .Lcleanup_sysc_restore
  1090. clg %r9,BASED(.Lcleanup_table+40) # .Lio_tif
  1091. jl 0f
  1092. clg %r9,BASED(.Lcleanup_table+48) # .Lio_restore
  1093. jl .Lcleanup_io_tif
  1094. clg %r9,BASED(.Lcleanup_table+56) # .Lio_done
  1095. jl .Lcleanup_io_restore
  1096. clg %r9,BASED(.Lcleanup_table+64) # psw_idle
  1097. jl 0f
  1098. clg %r9,BASED(.Lcleanup_table+72) # .Lpsw_idle_end
  1099. jl .Lcleanup_idle
  1100. clg %r9,BASED(.Lcleanup_table+80) # save_fpu_regs
  1101. jl 0f
  1102. clg %r9,BASED(.Lcleanup_table+88) # .Lsave_fpu_regs_end
  1103. jl .Lcleanup_save_fpu_regs
  1104. clg %r9,BASED(.Lcleanup_table+96) # load_fpu_regs
  1105. jl 0f
  1106. clg %r9,BASED(.Lcleanup_table+104) # .Lload_fpu_regs_end
  1107. jl .Lcleanup_load_fpu_regs
  1108. 0: BR_EX %r14,%r11
  1109. .align 8
  1110. .Lcleanup_table:
  1111. .quad system_call
  1112. .quad .Lsysc_do_svc
  1113. .quad .Lsysc_tif
  1114. .quad .Lsysc_restore
  1115. .quad .Lsysc_done
  1116. .quad .Lio_tif
  1117. .quad .Lio_restore
  1118. .quad .Lio_done
  1119. .quad psw_idle
  1120. .quad .Lpsw_idle_end
  1121. .quad save_fpu_regs
  1122. .quad .Lsave_fpu_regs_end
  1123. .quad load_fpu_regs
  1124. .quad .Lload_fpu_regs_end
  1125. #if IS_ENABLED(CONFIG_KVM)
  1126. .Lcleanup_table_sie:
  1127. .quad .Lsie_gmap
  1128. .quad .Lsie_done
  1129. .Lcleanup_sie:
  1130. BPENTER __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
  1131. lg %r9,__SF_EMPTY(%r15) # get control block pointer
  1132. ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
  1133. lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
  1134. larl %r9,sie_exit # skip forward to sie_exit
  1135. BR_EX %r14,%r11
  1136. #endif
  1137. .Lcleanup_system_call:
  1138. # check if stpt has been executed
  1139. clg %r9,BASED(.Lcleanup_system_call_insn)
  1140. jh 0f
  1141. mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
  1142. cghi %r11,__LC_SAVE_AREA_ASYNC
  1143. je 0f
  1144. mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
  1145. 0: # check if stmg has been executed
  1146. clg %r9,BASED(.Lcleanup_system_call_insn+8)
  1147. jh 0f
  1148. mvc __LC_SAVE_AREA_SYNC(64),0(%r11)
  1149. 0: # check if base register setup + TIF bit load has been done
  1150. clg %r9,BASED(.Lcleanup_system_call_insn+16)
  1151. jhe 0f
  1152. # set up saved registers r10 and r12
  1153. stg %r10,16(%r11) # r10 last break
  1154. stg %r12,32(%r11) # r12 thread-info pointer
  1155. 0: # check if the user time update has been done
  1156. clg %r9,BASED(.Lcleanup_system_call_insn+24)
  1157. jh 0f
  1158. lg %r15,__LC_EXIT_TIMER
  1159. slg %r15,__LC_SYNC_ENTER_TIMER
  1160. alg %r15,__LC_USER_TIMER
  1161. stg %r15,__LC_USER_TIMER
  1162. 0: # check if the system time update has been done
  1163. clg %r9,BASED(.Lcleanup_system_call_insn+32)
  1164. jh 0f
  1165. lg %r15,__LC_LAST_UPDATE_TIMER
  1166. slg %r15,__LC_EXIT_TIMER
  1167. alg %r15,__LC_SYSTEM_TIMER
  1168. stg %r15,__LC_SYSTEM_TIMER
  1169. 0: # update accounting time stamp
  1170. mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
  1171. # do LAST_BREAK
  1172. lg %r9,16(%r11)
  1173. srag %r9,%r9,23
  1174. jz 0f
  1175. mvc __TI_last_break(8,%r12),16(%r11)
  1176. 0: BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
  1177. # set up saved register r11
  1178. lg %r15,__LC_KERNEL_STACK
  1179. la %r9,STACK_FRAME_OVERHEAD(%r15)
  1180. stg %r9,24(%r11) # r11 pt_regs pointer
  1181. # fill pt_regs
  1182. mvc __PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
  1183. stmg %r0,%r7,__PT_R0(%r9)
  1184. mvc __PT_PSW(16,%r9),__LC_SVC_OLD_PSW
  1185. mvc __PT_INT_CODE(4,%r9),__LC_SVC_ILC
  1186. xc __PT_FLAGS(8,%r9),__PT_FLAGS(%r9)
  1187. mvi __PT_FLAGS+7(%r9),_PIF_SYSCALL
  1188. # setup saved register r15
  1189. stg %r15,56(%r11) # r15 stack pointer
  1190. # set new psw address and exit
  1191. larl %r9,.Lsysc_do_svc
  1192. BR_EX %r14,%r11
  1193. .Lcleanup_system_call_insn:
  1194. .quad system_call
  1195. .quad .Lsysc_stmg
  1196. .quad .Lsysc_per
  1197. .quad .Lsysc_vtime+36
  1198. .quad .Lsysc_vtime+42
  1199. .Lcleanup_sysc_tif:
  1200. larl %r9,.Lsysc_tif
  1201. BR_EX %r14,%r11
  1202. .Lcleanup_sysc_restore:
  1203. # check if stpt has been executed
  1204. clg %r9,BASED(.Lcleanup_sysc_restore_insn)
  1205. jh 0f
  1206. mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
  1207. cghi %r11,__LC_SAVE_AREA_ASYNC
  1208. je 0f
  1209. mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
  1210. 0: clg %r9,BASED(.Lcleanup_sysc_restore_insn+8)
  1211. je 1f
  1212. lg %r9,24(%r11) # get saved pointer to pt_regs
  1213. mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
  1214. mvc 0(64,%r11),__PT_R8(%r9)
  1215. lmg %r0,%r7,__PT_R0(%r9)
  1216. 1: lmg %r8,%r9,__LC_RETURN_PSW
  1217. BR_EX %r14,%r11
  1218. .Lcleanup_sysc_restore_insn:
  1219. .quad .Lsysc_exit_timer
  1220. .quad .Lsysc_done - 4
  1221. .Lcleanup_io_tif:
  1222. larl %r9,.Lio_tif
  1223. BR_EX %r14,%r11
  1224. .Lcleanup_io_restore:
  1225. # check if stpt has been executed
  1226. clg %r9,BASED(.Lcleanup_io_restore_insn)
  1227. jh 0f
  1228. mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
  1229. 0: clg %r9,BASED(.Lcleanup_io_restore_insn+8)
  1230. je 1f
  1231. lg %r9,24(%r11) # get saved r11 pointer to pt_regs
  1232. mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
  1233. mvc 0(64,%r11),__PT_R8(%r9)
  1234. lmg %r0,%r7,__PT_R0(%r9)
  1235. 1: lmg %r8,%r9,__LC_RETURN_PSW
  1236. BR_EX %r14,%r11
  1237. .Lcleanup_io_restore_insn:
  1238. .quad .Lio_exit_timer
  1239. .quad .Lio_done - 4
  1240. .Lcleanup_idle:
  1241. # copy interrupt clock & cpu timer
  1242. mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
  1243. mvc __TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
  1244. cghi %r11,__LC_SAVE_AREA_ASYNC
  1245. je 0f
  1246. mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
  1247. mvc __TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
  1248. 0: # check if stck & stpt have been executed
  1249. clg %r9,BASED(.Lcleanup_idle_insn)
  1250. jhe 1f
  1251. mvc __CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
  1252. mvc __TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
  1253. 1: # calculate idle cycles
  1254. #ifdef CONFIG_SMP
  1255. clg %r9,BASED(.Lcleanup_idle_insn)
  1256. jl 3f
  1257. larl %r1,smp_cpu_mtid
  1258. llgf %r1,0(%r1)
  1259. ltgr %r1,%r1
  1260. jz 3f
  1261. .insn rsy,0xeb0000000017,%r1,5,__SF_EMPTY+80(%r15)
  1262. larl %r3,mt_cycles
  1263. ag %r3,__LC_PERCPU_OFFSET
  1264. la %r4,__SF_EMPTY+16(%r15)
  1265. 2: lg %r0,0(%r3)
  1266. slg %r0,0(%r4)
  1267. alg %r0,64(%r4)
  1268. stg %r0,0(%r3)
  1269. la %r3,8(%r3)
  1270. la %r4,8(%r4)
  1271. brct %r1,2b
  1272. #endif
  1273. 3: # account system time going idle
  1274. lg %r9,__LC_STEAL_TIMER
  1275. alg %r9,__CLOCK_IDLE_ENTER(%r2)
  1276. slg %r9,__LC_LAST_UPDATE_CLOCK
  1277. stg %r9,__LC_STEAL_TIMER
  1278. mvc __LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
  1279. lg %r9,__LC_SYSTEM_TIMER
  1280. alg %r9,__LC_LAST_UPDATE_TIMER
  1281. slg %r9,__TIMER_IDLE_ENTER(%r2)
  1282. stg %r9,__LC_SYSTEM_TIMER
  1283. mvc __LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
  1284. # prepare return psw
  1285. nihh %r8,0xfcfd # clear irq & wait state bits
  1286. lg %r9,48(%r11) # return from psw_idle
  1287. BR_EX %r14,%r11
  1288. .Lcleanup_idle_insn:
  1289. .quad .Lpsw_idle_lpsw
  1290. .Lcleanup_save_fpu_regs:
  1291. larl %r9,save_fpu_regs
  1292. BR_EX %r14,%r11
  1293. .Lcleanup_load_fpu_regs:
  1294. larl %r9,load_fpu_regs
  1295. BR_EX %r14,%r11
  1296. /*
  1297. * Integer constants
  1298. */
  1299. .align 8
  1300. .Lcritical_start:
  1301. .quad .L__critical_start
  1302. .Lcritical_length:
  1303. .quad .L__critical_end - .L__critical_start
  1304. #if IS_ENABLED(CONFIG_KVM)
  1305. .Lsie_critical_start:
  1306. .quad .Lsie_gmap
  1307. .Lsie_critical_length:
  1308. .quad .Lsie_done - .Lsie_gmap
  1309. #endif
  1310. .section .rodata, "a"
  1311. #define SYSCALL(esame,emu) .long esame
  1312. .globl sys_call_table
  1313. sys_call_table:
  1314. #include "syscalls.S"
  1315. #undef SYSCALL
  1316. #ifdef CONFIG_COMPAT
  1317. #define SYSCALL(esame,emu) .long emu
  1318. .globl sys_call_table_emu
  1319. sys_call_table_emu:
  1320. #include "syscalls.S"
  1321. #undef SYSCALL
  1322. #endif