entry.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 low-level entry points.
  4. *
  5. * Copyright IBM Corp. 1999, 2012
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. * Hartmut Penner (hp@de.ibm.com),
  8. * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
  9. */
  10. #include <linux/export.h>
  11. #include <linux/init.h>
  12. #include <linux/linkage.h>
  13. #include <asm/asm-extable.h>
  14. #include <asm/alternative.h>
  15. #include <asm/processor.h>
  16. #include <asm/cache.h>
  17. #include <asm/dwarf.h>
  18. #include <asm/errno.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/thread_info.h>
  21. #include <asm/asm-offsets.h>
  22. #include <asm/unistd.h>
  23. #include <asm/page.h>
  24. #include <asm/sigp.h>
  25. #include <asm/irq.h>
  26. #include <asm/fpu-insn.h>
  27. #include <asm/setup.h>
  28. #include <asm/nmi.h>
  29. #include <asm/nospec-insn.h>
  30. #include <asm/lowcore.h>
  31. _LPP_OFFSET = __LC_LPP
  32. .macro STBEAR address
  33. ALTERNATIVE "nop", ".insn s,0xb2010000,\address", ALT_FACILITY(193)
  34. .endm
  35. .macro LBEAR address
  36. ALTERNATIVE "nop", ".insn s,0xb2000000,\address", ALT_FACILITY(193)
  37. .endm
  38. .macro LPSWEY address, lpswe
  39. ALTERNATIVE_2 "b \lpswe;nopr", \
  40. ".insn siy,0xeb0000000071,\address,0", ALT_FACILITY(193), \
  41. __stringify(.insn siy,0xeb0000000071,LOWCORE_ALT_ADDRESS+\address,0), \
  42. ALT_LOWCORE
  43. .endm
  44. .macro MBEAR reg, lowcore
  45. ALTERNATIVE "brcl 0,0", __stringify(mvc __PT_LAST_BREAK(8,\reg),__LC_LAST_BREAK(\lowcore)),\
  46. ALT_FACILITY(193)
  47. .endm
  48. .macro CHECK_STACK savearea, lowcore
  49. #ifdef CONFIG_CHECK_STACK
  50. tml %r15,THREAD_SIZE - CONFIG_STACK_GUARD
  51. la %r14,\savearea(\lowcore)
  52. jz stack_overflow
  53. #endif
  54. .endm
  55. .macro CHECK_VMAP_STACK savearea, lowcore, oklabel
  56. #ifdef CONFIG_VMAP_STACK
  57. lgr %r14,%r15
  58. nill %r14,0x10000 - THREAD_SIZE
  59. oill %r14,STACK_INIT_OFFSET
  60. clg %r14,__LC_KERNEL_STACK(\lowcore)
  61. je \oklabel
  62. clg %r14,__LC_ASYNC_STACK(\lowcore)
  63. je \oklabel
  64. clg %r14,__LC_MCCK_STACK(\lowcore)
  65. je \oklabel
  66. clg %r14,__LC_NODAT_STACK(\lowcore)
  67. je \oklabel
  68. clg %r14,__LC_RESTART_STACK(\lowcore)
  69. je \oklabel
  70. la %r14,\savearea(\lowcore)
  71. j stack_overflow
  72. #else
  73. j \oklabel
  74. #endif
  75. .endm
  76. /*
  77. * The TSTMSK macro generates a test-under-mask instruction by
  78. * calculating the memory offset for the specified mask value.
  79. * Mask value can be any constant. The macro shifts the mask
  80. * value to calculate the memory offset for the test-under-mask
  81. * instruction.
  82. */
  83. .macro TSTMSK addr, mask, size=8, bytepos=0
  84. .if (\bytepos < \size) && (\mask >> 8)
  85. .if (\mask & 0xff)
  86. .error "Mask exceeds byte boundary"
  87. .endif
  88. TSTMSK \addr, "(\mask >> 8)", \size, "(\bytepos + 1)"
  89. .exitm
  90. .endif
  91. .ifeq \mask
  92. .error "Mask must not be zero"
  93. .endif
  94. off = \size - \bytepos - 1
  95. tm off+\addr, \mask
  96. .endm
  97. .macro BPOFF
  98. ALTERNATIVE "nop", ".insn rrf,0xb2e80000,0,0,12,0", ALT_SPEC(82)
  99. .endm
  100. .macro BPON
  101. ALTERNATIVE "nop", ".insn rrf,0xb2e80000,0,0,13,0", ALT_SPEC(82)
  102. .endm
  103. .macro BPENTER tif_ptr,tif_mask
  104. ALTERNATIVE "TSTMSK \tif_ptr,\tif_mask; jz .+8; .insn rrf,0xb2e80000,0,0,13,0", \
  105. "j .+12; nop; nop", ALT_SPEC(82)
  106. .endm
  107. .macro BPEXIT tif_ptr,tif_mask
  108. TSTMSK \tif_ptr,\tif_mask
  109. ALTERNATIVE "jz .+8; .insn rrf,0xb2e80000,0,0,12,0", \
  110. "jnz .+8; .insn rrf,0xb2e80000,0,0,13,0", ALT_SPEC(82)
  111. .endm
  112. #if IS_ENABLED(CONFIG_KVM)
  113. .macro SIEEXIT sie_control,lowcore
  114. lg %r9,\sie_control # get control block pointer
  115. ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
  116. lctlg %c1,%c1,__LC_KERNEL_ASCE(\lowcore) # load primary asce
  117. lg %r9,__LC_CURRENT(\lowcore)
  118. mvi __TI_sie(%r9),0
  119. larl %r9,sie_exit # skip forward to sie_exit
  120. .endm
  121. #endif
  122. .macro STACKLEAK_ERASE
  123. #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
  124. brasl %r14,stackleak_erase_on_task_stack
  125. #endif
  126. .endm
  127. GEN_BR_THUNK %r14
  128. .section .kprobes.text, "ax"
  129. .Ldummy:
  130. /*
  131. * The following nop exists only in order to avoid that the next
  132. * symbol starts at the beginning of the kprobes text section.
  133. * In that case there would be several symbols at the same address.
  134. * E.g. objdump would take an arbitrary symbol when disassembling
  135. * the code.
  136. * With the added nop in between this cannot happen.
  137. */
  138. nop 0
  139. /*
  140. * Scheduler resume function, called by __switch_to
  141. * gpr2 = (task_struct *)prev
  142. * gpr3 = (task_struct *)next
  143. * Returns:
  144. * gpr2 = prev
  145. */
  146. SYM_FUNC_START(__switch_to_asm)
  147. stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
  148. lghi %r4,__TASK_stack
  149. lghi %r1,__TASK_thread
  150. llill %r5,STACK_INIT_OFFSET
  151. stg %r15,__THREAD_ksp(%r1,%r2) # store kernel stack of prev
  152. lg %r15,0(%r4,%r3) # start of kernel stack of next
  153. agr %r15,%r5 # end of kernel stack of next
  154. GET_LC %r13
  155. stg %r3,__LC_CURRENT(%r13) # store task struct of next
  156. stg %r15,__LC_KERNEL_STACK(%r13) # store end of kernel stack
  157. lg %r15,__THREAD_ksp(%r1,%r3) # load kernel stack of next
  158. aghi %r3,__TASK_pid
  159. mvc __LC_CURRENT_PID(4,%r13),0(%r3) # store pid of next
  160. ALTERNATIVE "nop", "lpp _LPP_OFFSET(%r13)", ALT_FACILITY(40)
  161. lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
  162. BR_EX %r14
  163. SYM_FUNC_END(__switch_to_asm)
  164. #if IS_ENABLED(CONFIG_KVM)
  165. /*
  166. * __sie64a calling convention:
  167. * %r2 pointer to sie control block phys
  168. * %r3 pointer to sie control block virt
  169. * %r4 guest register save area
  170. * %r5 guest asce
  171. */
  172. SYM_FUNC_START(__sie64a)
  173. stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
  174. GET_LC %r13
  175. lg %r14,__LC_CURRENT(%r13)
  176. stg %r2,__SF_SIE_CONTROL_PHYS(%r15) # save sie block physical..
  177. stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses
  178. stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area
  179. stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce
  180. xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0
  181. mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags
  182. lmg %r0,%r13,0(%r4) # load guest gprs 0-13
  183. mvi __TI_sie(%r14),1
  184. lctlg %c1,%c1,__SF_SIE_GUEST_ASCE(%r15) # load primary asce
  185. lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer
  186. oi __SIE_PROG0C+3(%r14),1 # we are going into SIE now
  187. tm __SIE_PROG20+3(%r14),3 # last exit...
  188. jnz .Lsie_skip
  189. lg %r14,__SF_SIE_CONTROL_PHYS(%r15) # get sie block phys addr
  190. BPEXIT __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
  191. .Lsie_entry:
  192. sie 0(%r14)
  193. # Let the next instruction be NOP to avoid triggering a machine check
  194. # and handling it in a guest as result of the instruction execution.
  195. nopr 7
  196. .Lsie_leave:
  197. BPOFF
  198. BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
  199. .Lsie_skip:
  200. lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer
  201. ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
  202. GET_LC %r14
  203. lctlg %c1,%c1,__LC_KERNEL_ASCE(%r14) # load primary asce
  204. lg %r14,__LC_CURRENT(%r14)
  205. mvi __TI_sie(%r14),0
  206. # some program checks are suppressing. C code (e.g. do_protection_exception)
  207. # will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There
  208. # are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable.
  209. # Other instructions between __sie64a and .Lsie_done should not cause program
  210. # interrupts. So lets use 3 nops as a landing pad for all possible rewinds.
  211. .Lrewind_pad6:
  212. nopr 7
  213. .Lrewind_pad4:
  214. nopr 7
  215. .Lrewind_pad2:
  216. nopr 7
  217. SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)
  218. lg %r14,__SF_SIE_SAVEAREA(%r15) # load guest register save area
  219. stmg %r0,%r13,0(%r14) # save guest gprs 0-13
  220. xgr %r0,%r0 # clear guest registers to
  221. xgr %r1,%r1 # prevent speculative use
  222. xgr %r3,%r3
  223. xgr %r4,%r4
  224. xgr %r5,%r5
  225. lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
  226. lg %r2,__SF_SIE_REASON(%r15) # return exit reason code
  227. BR_EX %r14
  228. .Lsie_fault:
  229. lghi %r14,-EFAULT
  230. stg %r14,__SF_SIE_REASON(%r15) # set exit reason code
  231. j sie_exit
  232. EX_TABLE(.Lrewind_pad6,.Lsie_fault)
  233. EX_TABLE(.Lrewind_pad4,.Lsie_fault)
  234. EX_TABLE(.Lrewind_pad2,.Lsie_fault)
  235. EX_TABLE(sie_exit,.Lsie_fault)
  236. SYM_FUNC_END(__sie64a)
  237. EXPORT_SYMBOL(__sie64a)
  238. EXPORT_SYMBOL(sie_exit)
  239. #endif
  240. /*
  241. * SVC interrupt handler routine. System calls are synchronous events and
  242. * are entered with interrupts disabled.
  243. */
  244. SYM_CODE_START(system_call)
  245. STMG_LC %r8,%r15,__LC_SAVE_AREA
  246. GET_LC %r13
  247. stpt __LC_SYS_ENTER_TIMER(%r13)
  248. BPOFF
  249. lghi %r14,0
  250. .Lsysc_per:
  251. STBEAR __LC_LAST_BREAK(%r13)
  252. lctlg %c1,%c1,__LC_KERNEL_ASCE(%r13)
  253. lg %r15,__LC_KERNEL_STACK(%r13)
  254. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  255. stmg %r0,%r7,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  256. # clear user controlled register to prevent speculative use
  257. xgr %r0,%r0
  258. xgr %r1,%r1
  259. xgr %r4,%r4
  260. xgr %r5,%r5
  261. xgr %r6,%r6
  262. xgr %r7,%r7
  263. xgr %r8,%r8
  264. xgr %r9,%r9
  265. xgr %r10,%r10
  266. xgr %r11,%r11
  267. la %r2,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
  268. mvc __PT_R8(64,%r2),__LC_SAVE_AREA(%r13)
  269. MBEAR %r2,%r13
  270. lgr %r3,%r14
  271. brasl %r14,__do_syscall
  272. STACKLEAK_ERASE
  273. lctlg %c1,%c1,__LC_USER_ASCE(%r13)
  274. mvc __LC_RETURN_PSW(16,%r13),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
  275. BPON
  276. LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15)
  277. stpt __LC_EXIT_TIMER(%r13)
  278. lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  279. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
  280. SYM_CODE_END(system_call)
  281. #
  282. # a new process exits the kernel with ret_from_fork
  283. #
  284. SYM_CODE_START(ret_from_fork)
  285. lgr %r3,%r11
  286. brasl %r14,__ret_from_fork
  287. STACKLEAK_ERASE
  288. GET_LC %r13
  289. lctlg %c1,%c1,__LC_USER_ASCE(%r13)
  290. mvc __LC_RETURN_PSW(16,%r13),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
  291. BPON
  292. LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15)
  293. stpt __LC_EXIT_TIMER(%r13)
  294. lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  295. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
  296. SYM_CODE_END(ret_from_fork)
  297. /*
  298. * Program check handler routine
  299. */
  300. SYM_CODE_START(pgm_check_handler)
  301. STMG_LC %r8,%r15,__LC_SAVE_AREA
  302. GET_LC %r13
  303. stpt __LC_SYS_ENTER_TIMER(%r13)
  304. BPOFF
  305. lgr %r10,%r15
  306. lmg %r8,%r9,__LC_PGM_OLD_PSW(%r13)
  307. tmhh %r8,0x0001 # coming from user space?
  308. jno .Lpgm_skip_asce
  309. lctlg %c1,%c1,__LC_KERNEL_ASCE(%r13)
  310. j 3f # -> fault in user space
  311. .Lpgm_skip_asce:
  312. 1: tmhh %r8,0x4000 # PER bit set in old PSW ?
  313. jnz 2f # -> enabled, can't be a double fault
  314. tm __LC_PGM_ILC+3(%r13),0x80 # check for per exception
  315. jnz .Lpgm_svcper # -> single stepped svc
  316. 2: CHECK_STACK __LC_SAVE_AREA,%r13
  317. aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  318. # CHECK_VMAP_STACK branches to stack_overflow or 4f
  319. CHECK_VMAP_STACK __LC_SAVE_AREA,%r13,4f
  320. 3: lg %r15,__LC_KERNEL_STACK(%r13)
  321. 4: la %r11,STACK_FRAME_OVERHEAD(%r15)
  322. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  323. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  324. stmg %r0,%r7,__PT_R0(%r11)
  325. mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
  326. mvc __PT_LAST_BREAK(8,%r11),__LC_PGM_LAST_BREAK(%r13)
  327. stctg %c1,%c1,__PT_CR1(%r11)
  328. #if IS_ENABLED(CONFIG_KVM)
  329. ltg %r12,__LC_GMAP(%r13)
  330. jz 5f
  331. clc __GMAP_ASCE(8,%r12), __PT_CR1(%r11)
  332. jne 5f
  333. BPENTER __SF_SIE_FLAGS(%r10),_TIF_ISOLATE_BP_GUEST
  334. SIEEXIT __SF_SIE_CONTROL(%r10),%r13
  335. #endif
  336. 5: stmg %r8,%r9,__PT_PSW(%r11)
  337. # clear user controlled registers to prevent speculative use
  338. xgr %r0,%r0
  339. xgr %r1,%r1
  340. xgr %r3,%r3
  341. xgr %r4,%r4
  342. xgr %r5,%r5
  343. xgr %r6,%r6
  344. xgr %r7,%r7
  345. lgr %r2,%r11
  346. brasl %r14,__do_pgm_check
  347. tmhh %r8,0x0001 # returning to user space?
  348. jno .Lpgm_exit_kernel
  349. STACKLEAK_ERASE
  350. lctlg %c1,%c1,__LC_USER_ASCE(%r13)
  351. BPON
  352. stpt __LC_EXIT_TIMER(%r13)
  353. .Lpgm_exit_kernel:
  354. mvc __LC_RETURN_PSW(16,%r13),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
  355. LBEAR STACK_FRAME_OVERHEAD+__PT_LAST_BREAK(%r15)
  356. lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  357. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
  358. #
  359. # single stepped system call
  360. #
  361. .Lpgm_svcper:
  362. mvc __LC_RETURN_PSW(8,%r13),__LC_SVC_NEW_PSW(%r13)
  363. larl %r14,.Lsysc_per
  364. stg %r14,__LC_RETURN_PSW+8(%r13)
  365. lghi %r14,1
  366. LBEAR __LC_PGM_LAST_BREAK(%r13)
  367. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE # branch to .Lsysc_per
  368. SYM_CODE_END(pgm_check_handler)
  369. /*
  370. * Interrupt handler macro used for external and IO interrupts.
  371. */
  372. .macro INT_HANDLER name,lc_old_psw,handler
  373. SYM_CODE_START(\name)
  374. STMG_LC %r8,%r15,__LC_SAVE_AREA
  375. GET_LC %r13
  376. stckf __LC_INT_CLOCK(%r13)
  377. stpt __LC_SYS_ENTER_TIMER(%r13)
  378. STBEAR __LC_LAST_BREAK(%r13)
  379. BPOFF
  380. lmg %r8,%r9,\lc_old_psw(%r13)
  381. tmhh %r8,0x0001 # interrupting from user ?
  382. jnz 1f
  383. #if IS_ENABLED(CONFIG_KVM)
  384. lg %r10,__LC_CURRENT(%r13)
  385. tm __TI_sie(%r10),0xff
  386. jz 0f
  387. BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
  388. SIEEXIT __SF_SIE_CONTROL(%r15),%r13
  389. #endif
  390. 0: CHECK_STACK __LC_SAVE_AREA,%r13
  391. aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
  392. j 2f
  393. 1: lctlg %c1,%c1,__LC_KERNEL_ASCE(%r13)
  394. lg %r15,__LC_KERNEL_STACK(%r13)
  395. 2: xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  396. la %r11,STACK_FRAME_OVERHEAD(%r15)
  397. stmg %r0,%r7,__PT_R0(%r11)
  398. # clear user controlled registers to prevent speculative use
  399. xgr %r0,%r0
  400. xgr %r1,%r1
  401. xgr %r3,%r3
  402. xgr %r4,%r4
  403. xgr %r5,%r5
  404. xgr %r6,%r6
  405. xgr %r7,%r7
  406. xgr %r10,%r10
  407. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  408. mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
  409. MBEAR %r11,%r13
  410. stmg %r8,%r9,__PT_PSW(%r11)
  411. lgr %r2,%r11 # pass pointer to pt_regs
  412. brasl %r14,\handler
  413. mvc __LC_RETURN_PSW(16,%r13),__PT_PSW(%r11)
  414. tmhh %r8,0x0001 # returning to user ?
  415. jno 2f
  416. STACKLEAK_ERASE
  417. lctlg %c1,%c1,__LC_USER_ASCE(%r13)
  418. BPON
  419. stpt __LC_EXIT_TIMER(%r13)
  420. 2: LBEAR __PT_LAST_BREAK(%r11)
  421. lmg %r0,%r15,__PT_R0(%r11)
  422. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
  423. SYM_CODE_END(\name)
  424. .endm
  425. .section .irqentry.text, "ax"
  426. INT_HANDLER ext_int_handler,__LC_EXT_OLD_PSW,do_ext_irq
  427. INT_HANDLER io_int_handler,__LC_IO_OLD_PSW,do_io_irq
  428. .section .kprobes.text, "ax"
  429. /*
  430. * Machine check handler routines
  431. */
  432. SYM_CODE_START(mcck_int_handler)
  433. BPOFF
  434. GET_LC %r13
  435. lmg %r8,%r9,__LC_MCK_OLD_PSW(%r13)
  436. TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_SYSTEM_DAMAGE
  437. jo .Lmcck_panic # yes -> rest of mcck code invalid
  438. TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_CR_VALID
  439. jno .Lmcck_panic # control registers invalid -> panic
  440. ptlb
  441. lay %r14,__LC_CPU_TIMER_SAVE_AREA(%r13)
  442. mvc __LC_MCCK_ENTER_TIMER(8,%r13),0(%r14)
  443. TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_CPU_TIMER_VALID
  444. jo 3f
  445. la %r14,__LC_SYS_ENTER_TIMER(%r13)
  446. clc 0(8,%r14),__LC_EXIT_TIMER(%r13)
  447. jl 1f
  448. la %r14,__LC_EXIT_TIMER(%r13)
  449. 1: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER(%r13)
  450. jl 2f
  451. la %r14,__LC_LAST_UPDATE_TIMER(%r13)
  452. 2: spt 0(%r14)
  453. mvc __LC_MCCK_ENTER_TIMER(8,%r13),0(%r14)
  454. 3: TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_PSW_MWP_VALID
  455. jno .Lmcck_panic
  456. tmhh %r8,0x0001 # interrupting from user ?
  457. jnz .Lmcck_user
  458. TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_PSW_IA_VALID
  459. jno .Lmcck_panic
  460. #if IS_ENABLED(CONFIG_KVM)
  461. lg %r10,__LC_CURRENT(%r13)
  462. tm __TI_sie(%r10),0xff
  463. jz .Lmcck_user
  464. # Need to compare the address instead of __TI_SIE flag.
  465. # Otherwise there would be a race between setting the flag
  466. # and entering SIE (or leaving and clearing the flag). This
  467. # would cause machine checks targeted at the guest to be
  468. # handled by the host.
  469. larl %r14,.Lsie_entry
  470. clgrjl %r9,%r14, 4f
  471. larl %r14,.Lsie_leave
  472. clgrjhe %r9,%r14, 4f
  473. lg %r10,__LC_PCPU(%r13)
  474. oi __PCPU_FLAGS+7(%r10), _CIF_MCCK_GUEST
  475. 4: BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
  476. SIEEXIT __SF_SIE_CONTROL(%r15),%r13
  477. #endif
  478. .Lmcck_user:
  479. lg %r15,__LC_MCCK_STACK(%r13)
  480. la %r11,STACK_FRAME_OVERHEAD(%r15)
  481. stctg %c1,%c1,__PT_CR1(%r11)
  482. lctlg %c1,%c1,__LC_KERNEL_ASCE(%r13)
  483. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  484. lay %r14,__LC_GPREGS_SAVE_AREA(%r13)
  485. mvc __PT_R0(128,%r11),0(%r14)
  486. # clear user controlled registers to prevent speculative use
  487. xgr %r0,%r0
  488. xgr %r1,%r1
  489. xgr %r3,%r3
  490. xgr %r4,%r4
  491. xgr %r5,%r5
  492. xgr %r6,%r6
  493. xgr %r7,%r7
  494. xgr %r10,%r10
  495. stmg %r8,%r9,__PT_PSW(%r11)
  496. xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
  497. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  498. lgr %r2,%r11 # pass pointer to pt_regs
  499. brasl %r14,s390_do_machine_check
  500. lctlg %c1,%c1,__PT_CR1(%r11)
  501. lmg %r0,%r10,__PT_R0(%r11)
  502. mvc __LC_RETURN_MCCK_PSW(16,%r13),__PT_PSW(%r11) # move return PSW
  503. tm __LC_RETURN_MCCK_PSW+1(%r13),0x01 # returning to user ?
  504. jno 0f
  505. BPON
  506. stpt __LC_EXIT_TIMER(%r13)
  507. 0: ALTERNATIVE "brcl 0,0", __stringify(lay %r12,__LC_LAST_BREAK_SAVE_AREA(%r13)),\
  508. ALT_FACILITY(193)
  509. LBEAR 0(%r12)
  510. lmg %r11,%r15,__PT_R11(%r11)
  511. LPSWEY __LC_RETURN_MCCK_PSW,__LC_RETURN_MCCK_LPSWE
  512. .Lmcck_panic:
  513. /*
  514. * Iterate over all possible CPU addresses in the range 0..0xffff
  515. * and stop each CPU using signal processor. Use compare and swap
  516. * to allow just one CPU-stopper and prevent concurrent CPUs from
  517. * stopping each other while leaving the others running.
  518. */
  519. lhi %r5,0
  520. lhi %r6,1
  521. larl %r7,stop_lock
  522. cs %r5,%r6,0(%r7) # single CPU-stopper only
  523. jnz 4f
  524. larl %r7,this_cpu
  525. stap 0(%r7) # this CPU address
  526. lh %r4,0(%r7)
  527. nilh %r4,0
  528. lhi %r0,1
  529. sll %r0,16 # CPU counter
  530. lhi %r3,0 # next CPU address
  531. 0: cr %r3,%r4
  532. je 2f
  533. 1: sigp %r1,%r3,SIGP_STOP # stop next CPU
  534. brc SIGP_CC_BUSY,1b
  535. 2: ahi %r3,1
  536. brct %r0,0b
  537. 3: sigp %r1,%r4,SIGP_STOP # stop this CPU
  538. brc SIGP_CC_BUSY,3b
  539. 4: j 4b
  540. SYM_CODE_END(mcck_int_handler)
  541. SYM_CODE_START(restart_int_handler)
  542. ALTERNATIVE "nop", "lpp _LPP_OFFSET", ALT_FACILITY(40)
  543. stg %r15,__LC_SAVE_AREA_RESTART
  544. TSTMSK __LC_RESTART_FLAGS,RESTART_FLAG_CTLREGS,4
  545. jz 0f
  546. lctlg %c0,%c15,__LC_CREGS_SAVE_AREA
  547. 0: larl %r15,daton_psw
  548. lpswe 0(%r15) # turn dat on, keep irqs off
  549. .Ldaton:
  550. GET_LC %r15
  551. lg %r15,__LC_RESTART_STACK(%r15)
  552. xc STACK_FRAME_OVERHEAD(__PT_SIZE,%r15),STACK_FRAME_OVERHEAD(%r15)
  553. stmg %r0,%r14,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  554. GET_LC %r13
  555. mvc STACK_FRAME_OVERHEAD+__PT_R15(8,%r15),__LC_SAVE_AREA_RESTART(%r13)
  556. mvc STACK_FRAME_OVERHEAD+__PT_PSW(16,%r15),__LC_RST_OLD_PSW(%r13)
  557. xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
  558. lg %r1,__LC_RESTART_FN(%r13) # load fn, parm & source cpu
  559. lg %r2,__LC_RESTART_DATA(%r13)
  560. lgf %r3,__LC_RESTART_SOURCE(%r13)
  561. ltgr %r3,%r3 # test source cpu address
  562. jm 1f # negative -> skip source stop
  563. 0: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
  564. brc 10,0b # wait for status stored
  565. 1: basr %r14,%r1 # call function
  566. stap __SF_EMPTY(%r15) # store cpu address
  567. llgh %r3,__SF_EMPTY(%r15)
  568. 2: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
  569. brc 2,2b
  570. 3: j 3b
  571. SYM_CODE_END(restart_int_handler)
  572. __INIT
  573. SYM_CODE_START(early_pgm_check_handler)
  574. STMG_LC %r8,%r15,__LC_SAVE_AREA
  575. GET_LC %r13
  576. aghi %r15,-(STACK_FRAME_OVERHEAD+__PT_SIZE)
  577. la %r11,STACK_FRAME_OVERHEAD(%r15)
  578. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  579. stmg %r0,%r7,__PT_R0(%r11)
  580. mvc __PT_PSW(16,%r11),__LC_PGM_OLD_PSW(%r13)
  581. mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
  582. lgr %r2,%r11
  583. brasl %r14,__do_early_pgm_check
  584. mvc __LC_RETURN_PSW(16,%r13),STACK_FRAME_OVERHEAD+__PT_PSW(%r15)
  585. lmg %r0,%r15,STACK_FRAME_OVERHEAD+__PT_R0(%r15)
  586. LPSWEY __LC_RETURN_PSW,__LC_RETURN_LPSWE
  587. SYM_CODE_END(early_pgm_check_handler)
  588. __FINIT
  589. .section .kprobes.text, "ax"
  590. #if defined(CONFIG_CHECK_STACK) || defined(CONFIG_VMAP_STACK)
  591. /*
  592. * The synchronous or the asynchronous stack overflowed. We are dead.
  593. * No need to properly save the registers, we are going to panic anyway.
  594. * Setup a pt_regs so that show_trace can provide a good call trace.
  595. */
  596. SYM_CODE_START(stack_overflow)
  597. GET_LC %r15
  598. lg %r15,__LC_NODAT_STACK(%r15) # change to panic stack
  599. la %r11,STACK_FRAME_OVERHEAD(%r15)
  600. stmg %r0,%r7,__PT_R0(%r11)
  601. stmg %r8,%r9,__PT_PSW(%r11)
  602. mvc __PT_R8(64,%r11),0(%r14)
  603. GET_LC %r2
  604. mvc __PT_ORIG_GPR2(8,%r11),__LC_PGM_LAST_BREAK(%r2)
  605. xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
  606. lgr %r2,%r11 # pass pointer to pt_regs
  607. jg kernel_stack_overflow
  608. SYM_CODE_END(stack_overflow)
  609. #endif
  610. .section .data, "aw"
  611. .balign 4
  612. SYM_DATA_LOCAL(stop_lock, .long 0)
  613. SYM_DATA_LOCAL(this_cpu, .short 0)
  614. .balign 8
  615. SYM_DATA_START_LOCAL(daton_psw)
  616. .quad PSW_KERNEL_BITS
  617. .quad .Ldaton
  618. SYM_DATA_END(daton_psw)
  619. .section .rodata, "a"
  620. .balign 8
  621. #define SYSCALL(esame,emu) .quad __s390x_ ## esame
  622. SYM_DATA_START(sys_call_table)
  623. #include "asm/syscall_table.h"
  624. SYM_DATA_END(sys_call_table)
  625. #undef SYSCALL
  626. #ifdef CONFIG_COMPAT
  627. #define SYSCALL(esame,emu) .quad __s390_ ## emu
  628. SYM_DATA_START(sys_call_table_emu)
  629. #include "asm/syscall_table.h"
  630. SYM_DATA_END(sys_call_table_emu)
  631. #undef SYSCALL
  632. #endif