blob: a316cd6999ad9712defdf46db85e16eb429aebcb [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * S390 low-level entry points.
4 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02005 * Copyright IBM Corp. 1999, 2012
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
Heiko Carstens25d83cb2006-09-28 16:56:37 +02007 * Hartmut Penner (hp@de.ibm.com),
8 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
Heiko Carstens77fa2242005-06-25 14:55:30 -07009 * Heiko Carstens <heiko.carstens@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Heiko Carstens2bc89b52008-02-05 16:50:40 +010012#include <linux/init.h>
Jan Glauber144d6342011-07-24 10:48:19 +020013#include <linux/linkage.h>
Heiko Carstenseb608fb2012-09-05 13:26:11 +020014#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/cache.h>
Martin Schwidefsky3037a522017-10-12 13:24:48 +020016#include <asm/ctl_reg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/errno.h>
18#include <asm/ptrace.h>
19#include <asm/thread_info.h>
Sam Ravnborg0013a852005-09-09 20:57:26 +020020#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/unistd.h>
22#include <asm/page.h>
Heiko Carstenseb546192012-06-04 15:05:43 +020023#include <asm/sigp.h>
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +020024#include <asm/irq.h>
Hendrik Brueckner9977e882015-06-10 12:53:42 +020025#include <asm/vx-insn.h>
Hendrik Brueckner83abeff2015-10-01 17:02:48 +020026#include <asm/setup.h>
27#include <asm/nmi.h>
Al Viro711f5df2016-01-12 13:30:03 -050028#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Martin Schwidefskyc5328902011-12-27 11:27:15 +010030__PT_R0 = __PT_GPRS
31__PT_R1 = __PT_GPRS + 8
32__PT_R2 = __PT_GPRS + 16
33__PT_R3 = __PT_GPRS + 24
34__PT_R4 = __PT_GPRS + 32
35__PT_R5 = __PT_GPRS + 40
36__PT_R6 = __PT_GPRS + 48
37__PT_R7 = __PT_GPRS + 56
38__PT_R8 = __PT_GPRS + 64
39__PT_R9 = __PT_GPRS + 72
40__PT_R10 = __PT_GPRS + 80
41__PT_R11 = __PT_GPRS + 88
42__PT_R12 = __PT_GPRS + 96
43__PT_R13 = __PT_GPRS + 104
44__PT_R14 = __PT_GPRS + 112
45__PT_R15 = __PT_GPRS + 120
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Heiko Carstens3a890382016-11-14 14:39:16 +010047STACK_SHIFT = PAGE_SHIFT + THREAD_SIZE_ORDER
Linus Torvalds1da177e2005-04-16 15:20:36 -070048STACK_SIZE = 1 << STACK_SHIFT
Martin Schwidefskydc7ee002013-04-24 10:20:43 +020049STACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Jan Willeke2a0a5b22014-09-22 16:39:06 +020051_TIF_WORK = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Linus Torvalds76f19482017-05-02 18:24:16 -070052 _TIF_UPROBE | _TIF_GUARDED_STORAGE | _TIF_PATCH_PENDING)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020053_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
54 _TIF_SYSCALL_TRACEPOINT)
Heiko Carstensb5a882f2017-02-17 08:13:28 +010055_CIF_WORK = (_CIF_MCCK_PENDING | _CIF_ASCE_PRIMARY | \
56 _CIF_ASCE_SECONDARY | _CIF_FPU)
Martin Schwidefsky23fefe12017-06-07 14:10:24 +020057_PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Hendrik Brueckner9977e882015-06-10 12:53:42 +020059#define BASED(name) name-cleanup_critical(%r13)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Martin Schwidefskyc5328902011-12-27 11:27:15 +010061 .macro TRACE_IRQS_ON
62#ifdef CONFIG_TRACE_IRQFLAGS
63 basr %r2,%r0
64 brasl %r14,trace_hardirqs_on_caller
65#endif
66 .endm
67
68 .macro TRACE_IRQS_OFF
69#ifdef CONFIG_TRACE_IRQFLAGS
70 basr %r2,%r0
71 brasl %r14,trace_hardirqs_off_caller
72#endif
73 .endm
74
75 .macro LOCKDEP_SYS_EXIT
76#ifdef CONFIG_LOCKDEP
77 tm __PT_PSW+1(%r11),0x01 # returning to user ?
78 jz .+10
79 brasl %r14,lockdep_sys_exit
80#endif
81 .endm
82
Martin Schwidefskyc5328902011-12-27 11:27:15 +010083 .macro CHECK_STACK stacksize,savearea
Martin Schwidefsky63b12242006-06-29 14:58:05 +020084#ifdef CONFIG_CHECK_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +010085 tml %r15,\stacksize - CONFIG_STACK_GUARD
86 lghi %r14,\savearea
87 jz stack_overflow
Martin Schwidefsky63b12242006-06-29 14:58:05 +020088#endif
Martin Schwidefsky63b12242006-06-29 14:58:05 +020089 .endm
90
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +020091 .macro SWITCH_ASYNC savearea,timer
Martin Schwidefskyc5328902011-12-27 11:27:15 +010092 tmhh %r8,0x0001 # interrupting from user ?
93 jnz 1f
94 lgr %r14,%r9
95 slg %r14,BASED(.Lcritical_start)
96 clg %r14,BASED(.Lcritical_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 jhe 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +010098 lghi %r11,\savearea # inside critical section, do cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 brasl %r14,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100100 tmhh %r8,0x0001 # retest problem state after cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 jnz 1f
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +02001020: lg %r14,__LC_ASYNC_STACK # are we already on the async stack?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 slgr %r14,%r15
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +0200104 srag %r14,%r14,STACK_SHIFT
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200105 jnz 2f
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +0200106 CHECK_STACK 1<<STACK_SHIFT,\savearea
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200107 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200108 j 3f
Martin Schwidefsky34525e12017-01-25 12:54:17 +01001091: UPDATE_VTIME %r14,%r15,\timer
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +02001102: lg %r15,__LC_ASYNC_STACK # load async stack
Martin Schwidefskya359bb12015-06-22 17:27:48 +02001113: la %r11,STACK_FRAME_OVERHEAD(%r15)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700112 .endm
113
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200114 .macro UPDATE_VTIME w1,w2,enter_timer
115 lg \w1,__LC_EXIT_TIMER
116 lg \w2,__LC_LAST_UPDATE_TIMER
117 slg \w1,\enter_timer
118 slg \w2,__LC_EXIT_TIMER
119 alg \w1,__LC_USER_TIMER
120 alg \w2,__LC_SYSTEM_TIMER
121 stg \w1,__LC_USER_TIMER
122 stg \w2,__LC_SYSTEM_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100123 mvc __LC_LAST_UPDATE_TIMER(8),\enter_timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200124 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200126 .macro REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100127 stg %r8,__LC_RETURN_PSW
128 ni __LC_RETURN_PSW,0xbf
129 ssm __LC_RETURN_PSW
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200130 .endm
131
Heiko Carstens473e66b2012-05-09 16:27:39 +0200132 .macro STCK savearea
Heiko Carstensd652d592012-05-14 10:35:22 +0200133#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
Heiko Carstens473e66b2012-05-09 16:27:39 +0200134 .insn s,0xb27c0000,\savearea # store clock fast
135#else
136 .insn s,0xb2050000,\savearea # store clock
137#endif
138 .endm
139
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200140 /*
141 * The TSTMSK macro generates a test-under-mask instruction by
142 * calculating the memory offset for the specified mask value.
143 * Mask value can be any constant. The macro shifts the mask
144 * value to calculate the memory offset for the test-under-mask
145 * instruction.
146 */
147 .macro TSTMSK addr, mask, size=8, bytepos=0
148 .if (\bytepos < \size) && (\mask >> 8)
149 .if (\mask & 0xff)
150 .error "Mask exceeds byte boundary"
151 .endif
152 TSTMSK \addr, "(\mask >> 8)", \size, "(\bytepos + 1)"
153 .exitm
154 .endif
155 .ifeq \mask
156 .error "Mask must not be zero"
157 .endif
158 off = \size - \bytepos - 1
159 tm off+\addr, \mask
160 .endm
161
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100162 .section .kprobes.text, "ax"
Heiko Carstens46210c42016-06-30 12:40:25 +0200163.Ldummy:
164 /*
165 * This nop exists only in order to avoid that __switch_to starts at
166 * the beginning of the kprobes text section. In that case we would
167 * have several symbols at the same address. E.g. objdump would take
168 * an arbitrary symbol name when disassembling this code.
169 * With the added nop in between the __switch_to symbol is unique
170 * again.
171 */
172 nop 0
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/*
175 * Scheduler resume function, called by switch_to
176 * gpr2 = (task_struct *) prev
177 * gpr3 = (task_struct *) next
178 * Returns:
179 * gpr2 = prev
180 */
Jan Glauber144d6342011-07-24 10:48:19 +0200181ENTRY(__switch_to)
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200182 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
Martin Schwidefsky3827ec32015-07-20 10:01:46 +0200183 lgr %r1,%r2
184 aghi %r1,__TASK_thread # thread_struct of prev task
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100185 lg %r5,__TASK_stack(%r3) # start of kernel stack of next
Martin Schwidefsky3827ec32015-07-20 10:01:46 +0200186 stg %r15,__THREAD_ksp(%r1) # store kernel stack of prev
187 lgr %r1,%r3
188 aghi %r1,__TASK_thread # thread_struct of next task
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200189 lgr %r15,%r5
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200190 aghi %r15,STACK_INIT # end of kernel stack of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200191 stg %r3,__LC_CURRENT # store task struct of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200192 stg %r15,__LC_KERNEL_STACK # store end of kernel stack
Martin Schwidefsky3827ec32015-07-20 10:01:46 +0200193 lg %r15,__THREAD_ksp(%r1) # load kernel stack of next
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200194 mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200195 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200196 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
197 bzr %r14
198 .insn s,0xb2800000,__LC_LPP # set program parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 br %r14
200
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100201.L__critical_start:
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200202
203#if IS_ENABLED(CONFIG_KVM)
204/*
205 * sie64a calling convention:
206 * %r2 pointer to sie control block
207 * %r3 guest register save area
208 */
209ENTRY(sie64a)
210 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
211 stg %r2,__SF_EMPTY(%r15) # save control block pointer
212 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200213 xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # reason code = 0
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200214 TSTMSK __LC_CPU_FLAGS,_CIF_FPU # load guest fp/vx registers ?
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200215 jno .Lsie_load_guest_gprs
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200216 brasl %r14,load_fpu_regs # load guest fp/vx regs
217.Lsie_load_guest_gprs:
218 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
219 lg %r14,__LC_GMAP # get gmap pointer
220 ltgr %r14,%r14
221 jz .Lsie_gmap
222 lctlg %c1,%c1,__GMAP_ASCE(%r14) # load primary asce
223.Lsie_gmap:
224 lg %r14,__SF_EMPTY(%r15) # get control block pointer
225 oi __SIE_PROG0C+3(%r14),1 # we are going into SIE now
226 tm __SIE_PROG20+3(%r14),3 # last exit...
227 jnz .Lsie_skip
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200228 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200229 jo .Lsie_skip # exit if fp/vx regs changed
QingFeng Haoc9295002017-06-07 11:30:42 +0200230.Lsie_entry:
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200231 sie 0(%r14)
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200232.Lsie_skip:
233 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
234 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
235.Lsie_done:
236# some program checks are suppressing. C code (e.g. do_protection_exception)
Christian Borntraegerc0e7bb32017-05-15 14:11:03 +0200237# will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There
238# are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable.
239# Other instructions between sie64a and .Lsie_done should not cause program
240# interrupts. So lets use 3 nops as a landing pad for all possible rewinds.
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200241# See also .Lcleanup_sie
Christian Borntraegerc0e7bb32017-05-15 14:11:03 +0200242.Lrewind_pad6:
243 nopr 7
244.Lrewind_pad4:
245 nopr 7
246.Lrewind_pad2:
247 nopr 7
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200248 .globl sie_exit
249sie_exit:
250 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
251 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
252 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200253 lg %r2,__SF_EMPTY+16(%r15) # return exit reason code
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200254 br %r14
255.Lsie_fault:
256 lghi %r14,-EFAULT
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200257 stg %r14,__SF_EMPTY+16(%r15) # set exit reason code
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200258 j sie_exit
259
Christian Borntraegerc0e7bb32017-05-15 14:11:03 +0200260 EX_TABLE(.Lrewind_pad6,.Lsie_fault)
261 EX_TABLE(.Lrewind_pad4,.Lsie_fault)
262 EX_TABLE(.Lrewind_pad2,.Lsie_fault)
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200263 EX_TABLE(sie_exit,.Lsie_fault)
Al Viro711f5df2016-01-12 13:30:03 -0500264EXPORT_SYMBOL(sie64a)
265EXPORT_SYMBOL(sie_exit)
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200266#endif
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*
269 * SVC interrupt handler routine. System calls are synchronous events and
270 * are executed with interrupts enabled.
271 */
272
Jan Glauber144d6342011-07-24 10:48:19 +0200273ENTRY(system_call)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100274 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100275.Lsysc_stmg:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100276 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100277 lg %r12,__LC_CURRENT
Martin Schwidefsky34525e12017-01-25 12:54:17 +0100278 lghi %r13,__TASK_thread
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200279 lghi %r14,_PIF_SYSCALL
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100280.Lsysc_per:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100281 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100282 la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200283.Lsysc_vtime:
Martin Schwidefsky34525e12017-01-25 12:54:17 +0100284 UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100285 stmg %r0,%r7,__PT_R0(%r11)
286 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
287 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100288 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200289 stg %r14,__PT_FLAGS(%r11)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100290.Lsysc_do_svc:
Martin Schwidefskyef280c82016-11-08 12:33:38 +0100291 # load address of system call table
Martin Schwidefskyef280c82016-11-08 12:33:38 +0100292 lg %r10,__THREAD_sysc_table(%r13,%r12)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100293 llgh %r8,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100294 slag %r8,%r8,2 # shift and test for svc 0
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100295 jnz .Lsysc_nr_ok
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 # svc 0: system call number in %r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100297 llgfr %r1,%r1 # clear high word in r1
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200298 cghi %r1,NR_syscalls
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100299 jnl .Lsysc_nr_ok
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100300 sth %r1,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100301 slag %r8,%r1,2
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100302.Lsysc_nr_ok:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100303 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
304 stg %r2,__PT_ORIG_GPR2(%r11)
305 stg %r7,STACK_FRAME_OVERHEAD(%r15)
306 lgf %r9,0(%r8,%r10) # get system call add.
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200307 TSTMSK __TI_flags(%r12),_TIF_TRACE
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100308 jnz .Lsysc_tracesys
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100309 basr %r14,%r9 # call sys_xxxx
310 stg %r2,__PT_R2(%r11) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100312.Lsysc_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200313 LOCKDEP_SYS_EXIT
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100314.Lsysc_tif:
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200315 TSTMSK __PT_FLAGS(%r11),_PIF_WORK
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100316 jnz .Lsysc_work
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200317 TSTMSK __TI_flags(%r12),_TIF_WORK
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100318 jnz .Lsysc_work # check for work
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200319 TSTMSK __LC_CPU_FLAGS,_CIF_WORK
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100320 jnz .Lsysc_work
321.Lsysc_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100322 lg %r14,__LC_VDSO_PER_CPU
323 lmg %r0,%r10,__PT_R0(%r11)
324 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +0200325.Lsysc_exit_timer:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100326 stpt __LC_EXIT_TIMER
327 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
328 lmg %r11,%r15,__PT_R11(%r11)
329 lpswe __LC_RETURN_PSW
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100330.Lsysc_done:
Heiko Carstens411788e2007-11-20 11:13:32 +0100331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200333# One of the work bits is on. Find out which one.
334#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100335.Lsysc_work:
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200336 TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100337 jo .Lsysc_mcck_pending
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200338 TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100339 jo .Lsysc_reschedule
Martin Schwidefsky23fefe12017-06-07 14:10:24 +0200340 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
341 jo .Lsysc_syscall_restart
Jan Willeke2a0a5b22014-09-22 16:39:06 +0200342#ifdef CONFIG_UPROBES
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200343 TSTMSK __TI_flags(%r12),_TIF_UPROBE
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100344 jo .Lsysc_uprobe_notify
Jan Willeke2a0a5b22014-09-22 16:39:06 +0200345#endif
Martin Schwidefsky916cda12016-01-26 14:10:34 +0100346 TSTMSK __TI_flags(%r12),_TIF_GUARDED_STORAGE
347 jo .Lsysc_guarded_storage
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200348 TSTMSK __PT_FLAGS(%r11),_PIF_PER_TRAP
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100349 jo .Lsysc_singlestep
Miroslav Benes2f09ca62017-02-13 19:42:34 -0600350#ifdef CONFIG_LIVEPATCH
351 TSTMSK __TI_flags(%r12),_TIF_PATCH_PENDING
352 jo .Lsysc_patch_pending # handle live patching just before
353 # signals and possible syscall restart
354#endif
Martin Schwidefsky23fefe12017-06-07 14:10:24 +0200355 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
356 jo .Lsysc_syscall_restart
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200357 TSTMSK __TI_flags(%r12),_TIF_SIGPENDING
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100358 jo .Lsysc_sigpending
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200359 TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100360 jo .Lsysc_notify_resume
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200361 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200362 jo .Lsysc_vxrs
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100363 TSTMSK __LC_CPU_FLAGS,(_CIF_ASCE_PRIMARY|_CIF_ASCE_SECONDARY)
364 jnz .Lsysc_asce
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100365 j .Lsysc_return # beware of critical section cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367#
368# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200369#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100370.Lsysc_reschedule:
371 larl %r14,.Lsysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100372 jg schedule
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374#
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200375# _CIF_MCCK_PENDING is set, call handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700376#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100377.Lsysc_mcck_pending:
378 larl %r14,.Lsysc_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200379 jg s390_handle_mcck # TIF bit will be cleared by handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700380
381#
Martin Schwidefsky0aaba412017-08-22 12:08:22 +0200382# _CIF_ASCE_PRIMARY and/or _CIF_ASCE_SECONDARY set, load user space asce
Heiko Carstens457f2182014-03-21 10:42:25 +0100383#
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100384.Lsysc_asce:
Martin Schwidefsky0aaba412017-08-22 12:08:22 +0200385 ni __LC_CPU_FLAGS+7,255-_CIF_ASCE_SECONDARY
386 lctlg %c7,%c7,__LC_VDSO_ASCE # load secondary asce
387 TSTMSK __LC_CPU_FLAGS,_CIF_ASCE_PRIMARY
388 jz .Lsysc_return
389#ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
390 tm __LC_STFLE_FAC_LIST+3,0x10 # has MVCOS ?
391 jnz .Lsysc_set_fs_fixup
Heiko Carstens606aa4a2017-02-17 08:12:30 +0100392 ni __LC_CPU_FLAGS+7,255-_CIF_ASCE_PRIMARY
Heiko Carstens457f2182014-03-21 10:42:25 +0100393 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky0aaba412017-08-22 12:08:22 +0200394 j .Lsysc_return
395.Lsysc_set_fs_fixup:
396#endif
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100397 larl %r14,.Lsysc_return
398 jg set_fs_fixup
Heiko Carstens457f2182014-03-21 10:42:25 +0100399
400#
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200401# CIF_FPU is set, restore floating-point controls and floating-point registers.
402#
403.Lsysc_vxrs:
404 larl %r14,.Lsysc_return
405 jg load_fpu_regs
406
407#
Roland McGrath02a029b2008-04-30 00:53:08 -0700408# _TIF_SIGPENDING is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100410.Lsysc_sigpending:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100411 lgr %r2,%r11 # pass pointer to pt_regs
412 brasl %r14,do_signal
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200413 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100414 jno .Lsysc_return
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100415.Lsysc_do_syscall:
416 lghi %r13,__TASK_thread
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100417 lmg %r2,%r7,__PT_R2(%r11) # load svc arguments
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100418 lghi %r1,0 # svc 0 returns -ENOSYS
419 j .Lsysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200422# _TIF_NOTIFY_RESUME is set, call do_notify_resume
423#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100424.Lsysc_notify_resume:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100425 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100426 larl %r14,.Lsysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100427 jg do_notify_resume
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200428
429#
Jan Willeke2a0a5b22014-09-22 16:39:06 +0200430# _TIF_UPROBE is set, call uprobe_notify_resume
431#
432#ifdef CONFIG_UPROBES
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100433.Lsysc_uprobe_notify:
Jan Willeke2a0a5b22014-09-22 16:39:06 +0200434 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100435 larl %r14,.Lsysc_return
Jan Willeke2a0a5b22014-09-22 16:39:06 +0200436 jg uprobe_notify_resume
437#endif
438
439#
Martin Schwidefsky916cda12016-01-26 14:10:34 +0100440# _TIF_GUARDED_STORAGE is set, call guarded_storage_load
441#
442.Lsysc_guarded_storage:
443 lgr %r2,%r11 # pass pointer to pt_regs
444 larl %r14,.Lsysc_return
445 jg gs_load_bc_cb
Linus Torvalds76f19482017-05-02 18:24:16 -0700446#
Miroslav Benes2f09ca62017-02-13 19:42:34 -0600447# _TIF_PATCH_PENDING is set, call klp_update_patch_state
448#
449#ifdef CONFIG_LIVEPATCH
450.Lsysc_patch_pending:
451 lg %r2,__LC_CURRENT # pass pointer to task struct
452 larl %r14,.Lsysc_return
453 jg klp_update_patch_state
454#endif
Martin Schwidefsky916cda12016-01-26 14:10:34 +0100455
456#
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200457# _PIF_PER_TRAP is set, call do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100459.Lsysc_singlestep:
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200460 ni __PT_FLAGS+7(%r11),255-_PIF_PER_TRAP
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100461 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100462 larl %r14,.Lsysc_return
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100463 jg do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#
Martin Schwidefsky23fefe12017-06-07 14:10:24 +0200466# _PIF_SYSCALL_RESTART is set, repeat the current system call
467#
468.Lsysc_syscall_restart:
469 ni __PT_FLAGS+7(%r11),255-_PIF_SYSCALL_RESTART
470 lmg %r1,%r7,__PT_R1(%r11) # load svc arguments
471 lg %r2,__PT_ORIG_GPR2(%r11)
472 j .Lsysc_do_svc
473
474#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200475# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
476# and after the system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100478.Lsysc_tracesys:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100479 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 la %r3,0
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100481 llgh %r0,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100482 stg %r0,__PT_R2(%r11)
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200483 brasl %r14,do_syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 lghi %r0,NR_syscalls
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200485 clgr %r0,%r2
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100486 jnh .Lsysc_tracenogo
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100487 sllg %r8,%r2,2
488 lgf %r9,0(%r8,%r10)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100489.Lsysc_tracego:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100490 lmg %r3,%r7,__PT_R3(%r11)
491 stg %r7,STACK_FRAME_OVERHEAD(%r15)
492 lg %r2,__PT_ORIG_GPR2(%r11)
493 basr %r14,%r9 # call sys_xxx
494 stg %r2,__PT_R2(%r11) # store return value
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100495.Lsysc_tracenogo:
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200496 TSTMSK __TI_flags(%r12),_TIF_TRACE
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100497 jz .Lsysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100498 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100499 larl %r14,.Lsysc_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200500 jg do_syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502#
503# a new process exits the kernel with ret_from_fork
504#
Jan Glauber144d6342011-07-24 10:48:19 +0200505ENTRY(ret_from_fork)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100506 la %r11,STACK_FRAME_OVERHEAD(%r15)
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100507 lg %r12,__LC_CURRENT
Al Viro30dcb092012-10-11 15:30:14 -0400508 brasl %r14,schedule_tail
509 TRACE_IRQS_ON
510 ssm __LC_SVC_NEW_PSW # reenable interrupts
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100511 tm __PT_PSW+1(%r11),0x01 # forking a kernel thread ?
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100512 jne .Lsysc_tracenogo
Al Viro30dcb092012-10-11 15:30:14 -0400513 # it's a kernel thread
514 lmg %r9,%r10,__PT_R9(%r11) # load gprs
Al Viro37fe5d42012-09-10 18:03:41 -0400515ENTRY(kernel_thread_starter)
516 la %r2,0(%r10)
517 basr %r14,%r9
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100518 j .Lsysc_tracenogo
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520/*
521 * Program check handler routine
522 */
523
Jan Glauber144d6342011-07-24 10:48:19 +0200524ENTRY(pgm_check_handler)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100525 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100526 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
527 lg %r10,__LC_LAST_BREAK
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100528 lg %r12,__LC_CURRENT
Martin Schwidefskyc7713202017-10-05 08:44:26 +0200529 lghi %r11,0
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200530 larl %r13,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100531 lmg %r8,%r9,__LC_PGM_OLD_PSW
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100532 tmhh %r8,0x0001 # test problem state bit
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200533 jnz 2f # -> fault in user space
534#if IS_ENABLED(CONFIG_KVM)
Martin Schwidefsky0a5e2ec2017-10-05 08:29:47 +0200535 # cleanup critical section for program checks in sie64a
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200536 lgr %r14,%r9
537 slg %r14,BASED(.Lsie_critical_start)
538 clg %r14,BASED(.Lsie_critical_length)
539 jhe 0f
Martin Schwidefsky0a5e2ec2017-10-05 08:29:47 +0200540 lg %r14,__SF_EMPTY(%r15) # get control block pointer
541 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
542 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
543 larl %r9,sie_exit # skip forward to sie_exit
Martin Schwidefskyc7713202017-10-05 08:44:26 +0200544 lghi %r11,_PIF_GUEST_FAULT
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200545#endif
5460: tmhh %r8,0x4000 # PER bit set in old PSW ?
547 jnz 1f # -> enabled, can't be a double fault
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100548 tm __LC_PGM_ILC+3,0x80 # check for per exception
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100549 jnz .Lpgm_svcper # -> single stepped svc
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02005501: CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200551 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskyd9fcf2a2017-02-28 07:42:01 +0100552 j 4f
Martin Schwidefsky34525e12017-01-25 12:54:17 +01005532: UPDATE_VTIME %r14,%r15,__LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100554 lg %r15,__LC_KERNEL_STACK
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100555 lgr %r14,%r12
Martin Schwidefsky3827ec32015-07-20 10:01:46 +0200556 aghi %r14,__TASK_thread # pointer to thread_struct
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200557 lghi %r13,__LC_PGM_TDB
558 tm __LC_PGM_ILC+2,0x02 # check for transaction abort
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +0200559 jz 3f
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200560 mvc __THREAD_trap_tdb(256,%r14),0(%r13)
Martin Schwidefskyd9fcf2a2017-02-28 07:42:01 +01005613: stg %r10,__THREAD_last_break(%r14)
Martin Schwidefskyc7713202017-10-05 08:44:26 +02005624: lgr %r13,%r11
563 la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100564 stmg %r0,%r7,__PT_R0(%r11)
565 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
566 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100567 mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
568 mvc __PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
Martin Schwidefskyc7713202017-10-05 08:44:26 +0200569 stg %r13,__PT_FLAGS(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100570 stg %r10,__PT_ARGS(%r11)
571 tm __LC_PGM_ILC+3,0x80 # check for per exception
Martin Schwidefskyd9fcf2a2017-02-28 07:42:01 +0100572 jz 5f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100573 tmhh %r8,0x0001 # kernel per event ?
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100574 jz .Lpgm_kprobe
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200575 oi __PT_FLAGS+7(%r11),_PIF_PER_TRAP
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200576 mvc __THREAD_per_address(8,%r14),__LC_PER_ADDRESS
Jens Freimann21ee7ff2014-02-26 16:32:46 +0100577 mvc __THREAD_per_cause(2,%r14),__LC_PER_CODE
578 mvc __THREAD_per_paid(1,%r14),__LC_PER_ACCESS_ID
Martin Schwidefskyd9fcf2a2017-02-28 07:42:01 +01005795: REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100580 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200581 larl %r1,pgm_check_table
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100582 llgh %r10,__PT_INT_CODE+2(%r11)
583 nill %r10,0x007f
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200584 sll %r10,2
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200585 je .Lpgm_return
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200586 lgf %r1,0(%r10,%r1) # load address of handler routine
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100587 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200588 basr %r14,%r1 # branch to interrupt-handler
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200589.Lpgm_return:
590 LOCKDEP_SYS_EXIT
591 tm __PT_PSW+1(%r11),0x01 # returning to user ?
592 jno .Lsysc_restore
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100593 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL
594 jo .Lsysc_do_syscall
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200595 j .Lsysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597#
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100598# PER event in supervisor state, must be kprobes
599#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100600.Lpgm_kprobe:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100601 REENABLE_IRQS
602 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
603 lgr %r2,%r11 # pass pointer to pt_regs
604 brasl %r14,do_per_trap
Martin Schwidefskya359bb12015-06-22 17:27:48 +0200605 j .Lpgm_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100606
607#
608# single stepped system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100610.Lpgm_svcper:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100611 mvc __LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
Martin Schwidefskyd24b98e2017-02-20 09:51:36 +0100612 lghi %r13,__TASK_thread
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100613 larl %r14,.Lsysc_per
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100614 stg %r14,__LC_RETURN_PSW+8
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200615 lghi %r14,_PIF_SYSCALL | _PIF_PER_TRAP
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100616 lpswe __LC_RETURN_PSW # branch to .Lsysc_per and enable irqs
Michael Grundy4ba069b2006-09-20 15:58:39 +0200617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/*
619 * IO interrupt handler routine
620 */
Jan Glauber144d6342011-07-24 10:48:19 +0200621ENTRY(io_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200622 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100623 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100624 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100625 lg %r12,__LC_CURRENT
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200626 larl %r13,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100627 lmg %r8,%r9,__LC_IO_OLD_PSW
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +0200628 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100629 stmg %r0,%r7,__PT_R0(%r11)
630 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
631 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200632 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200633 xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
Heiko Carstensdb7e0072015-08-15 11:42:21 +0200634 TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ
635 jo .Lio_restore
Heiko Carstens1f194a42006-07-03 00:24:46 -0700636 TRACE_IRQS_OFF
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100637 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100638.Lio_loop:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100639 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +0200640 lghi %r3,IO_INTERRUPT
641 tm __PT_INT_CODE+8(%r11),0x80 # adapter interrupt ?
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100642 jz .Lio_call
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +0200643 lghi %r3,THIN_INTERRUPT
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100644.Lio_call:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100645 brasl %r14,do_IRQ
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200646 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPAR
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100647 jz .Lio_return
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200648 tpi 0
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100649 jz .Lio_return
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200650 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100651 j .Lio_loop
652.Lio_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200653 LOCKDEP_SYS_EXIT
654 TRACE_IRQS_ON
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100655.Lio_tif:
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200656 TSTMSK __TI_flags(%r12),_TIF_WORK
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100657 jnz .Lio_work # there is work to do (signals etc.)
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200658 TSTMSK __LC_CPU_FLAGS,_CIF_WORK
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100659 jnz .Lio_work
660.Lio_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100661 lg %r14,__LC_VDSO_PER_CPU
662 lmg %r0,%r10,__PT_R0(%r11)
663 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +0200664.Lio_exit_timer:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100665 stpt __LC_EXIT_TIMER
666 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
667 lmg %r11,%r15,__PT_R11(%r11)
668 lpswe __LC_RETURN_PSW
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100669.Lio_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Martin Schwidefsky26889052008-05-07 09:22:52 +0200671#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200672# There is work todo, find out in which context we have been interrupted:
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200673# 1) if we return to user space we can do all _TIF_WORK work
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200674# 2) if we return to kernel code and kvm is enabled check if we need to
675# modify the psw to leave SIE
676# 3) if we return to kernel code and preemptive scheduling is enabled check
677# the preemption counter and if it is zero call preempt_schedule_irq
678# Before any work can be done, a switch to the kernel stack is required.
Martin Schwidefsky26889052008-05-07 09:22:52 +0200679#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100680.Lio_work:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100681 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100682 jo .Lio_work_user # yes -> do resched & signal
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200683#ifdef CONFIG_PREEMPT
Martin Schwidefsky26889052008-05-07 09:22:52 +0200684 # check for preemptive scheduling
Martin Schwidefskyc3601922016-10-25 12:21:44 +0200685 icm %r0,15,__LC_PREEMPT_COUNT
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100686 jnz .Lio_restore # preemption is disabled
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200687 TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100688 jno .Lio_restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100690 lg %r1,__PT_R15(%r11)
691 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
692 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
693 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
694 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 lgr %r15,%r1
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100696 # TRACE_IRQS_ON already done at .Lio_return, call
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200697 # TRACE_IRQS_OFF to keep things symmetrical
698 TRACE_IRQS_OFF
699 brasl %r14,preempt_schedule_irq
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100700 j .Lio_return
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200701#else
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100702 j .Lio_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200703#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200705#
706# Need to do work before returning to userspace, switch to kernel stack
707#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100708.Lio_work_user:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 lg %r1,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100710 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
711 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
712 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 lgr %r15,%r1
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#
716# One of the work bits is on. Find out which one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100718.Lio_work_tif:
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200719 TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100720 jo .Lio_mcck_pending
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200721 TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100722 jo .Lio_reschedule
Miroslav Benes2f09ca62017-02-13 19:42:34 -0600723#ifdef CONFIG_LIVEPATCH
724 TSTMSK __TI_flags(%r12),_TIF_PATCH_PENDING
725 jo .Lio_patch_pending
726#endif
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200727 TSTMSK __TI_flags(%r12),_TIF_SIGPENDING
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100728 jo .Lio_sigpending
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200729 TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100730 jo .Lio_notify_resume
Martin Schwidefsky916cda12016-01-26 14:10:34 +0100731 TSTMSK __TI_flags(%r12),_TIF_GUARDED_STORAGE
732 jo .Lio_guarded_storage
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200733 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200734 jo .Lio_vxrs
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100735 TSTMSK __LC_CPU_FLAGS,(_CIF_ASCE_PRIMARY|_CIF_ASCE_SECONDARY)
736 jnz .Lio_asce
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100737 j .Lio_return # beware of critical section cleanup
Christian Borntraeger0eaeafa2008-05-07 09:22:53 +0200738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200740# _CIF_MCCK_PENDING is set, call handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700741#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100742.Lio_mcck_pending:
743 # TRACE_IRQS_ON already done at .Lio_return
Heiko Carstensb771aea2007-07-27 12:29:18 +0200744 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200745 TRACE_IRQS_OFF
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100746 j .Lio_return
Heiko Carstens77fa2242005-06-25 14:55:30 -0700747
748#
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100749# _CIF_ASCE_PRIMARY and/or CIF_ASCE_SECONDARY set, load user space asce
Heiko Carstens457f2182014-03-21 10:42:25 +0100750#
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100751.Lio_asce:
Martin Schwidefsky0aaba412017-08-22 12:08:22 +0200752 ni __LC_CPU_FLAGS+7,255-_CIF_ASCE_SECONDARY
753 lctlg %c7,%c7,__LC_VDSO_ASCE # load secondary asce
754 TSTMSK __LC_CPU_FLAGS,_CIF_ASCE_PRIMARY
755 jz .Lio_return
756#ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
757 tm __LC_STFLE_FAC_LIST+3,0x10 # has MVCOS ?
758 jnz .Lio_set_fs_fixup
Heiko Carstens606aa4a2017-02-17 08:12:30 +0100759 ni __LC_CPU_FLAGS+7,255-_CIF_ASCE_PRIMARY
Heiko Carstens457f2182014-03-21 10:42:25 +0100760 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky0aaba412017-08-22 12:08:22 +0200761 j .Lio_return
762.Lio_set_fs_fixup:
763#endif
Heiko Carstensb5a882f2017-02-17 08:13:28 +0100764 larl %r14,.Lio_return
765 jg set_fs_fixup
Heiko Carstens457f2182014-03-21 10:42:25 +0100766
767#
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200768# CIF_FPU is set, restore floating-point controls and floating-point registers.
769#
770.Lio_vxrs:
771 larl %r14,.Lio_return
772 jg load_fpu_regs
773
774#
Martin Schwidefsky916cda12016-01-26 14:10:34 +0100775# _TIF_GUARDED_STORAGE is set, call guarded_storage_load
776#
777.Lio_guarded_storage:
778 # TRACE_IRQS_ON already done at .Lio_return
779 ssm __LC_SVC_NEW_PSW # reenable interrupts
780 lgr %r2,%r11 # pass pointer to pt_regs
781 brasl %r14,gs_load_bc_cb
782 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
783 TRACE_IRQS_OFF
784 j .Lio_return
785
786#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200788#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100789.Lio_reschedule:
790 # TRACE_IRQS_ON already done at .Lio_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100791 ssm __LC_SVC_NEW_PSW # reenable interrupts
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200792 brasl %r14,schedule # call scheduler
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100793 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100794 TRACE_IRQS_OFF
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100795 j .Lio_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797#
Miroslav Benes2f09ca62017-02-13 19:42:34 -0600798# _TIF_PATCH_PENDING is set, call klp_update_patch_state
799#
800#ifdef CONFIG_LIVEPATCH
801.Lio_patch_pending:
802 lg %r2,__LC_CURRENT # pass pointer to task struct
803 larl %r14,.Lio_return
804 jg klp_update_patch_state
805#endif
806
807#
Roland McGrath02a029b2008-04-30 00:53:08 -0700808# _TIF_SIGPENDING or is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100810.Lio_sigpending:
811 # TRACE_IRQS_ON already done at .Lio_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100812 ssm __LC_SVC_NEW_PSW # reenable interrupts
813 lgr %r2,%r11 # pass pointer to pt_regs
814 brasl %r14,do_signal
815 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100816 TRACE_IRQS_OFF
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100817 j .Lio_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200819#
820# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
821#
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100822.Lio_notify_resume:
823 # TRACE_IRQS_ON already done at .Lio_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100824 ssm __LC_SVC_NEW_PSW # reenable interrupts
825 lgr %r2,%r11 # pass pointer to pt_regs
826 brasl %r14,do_notify_resume
827 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200828 TRACE_IRQS_OFF
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100829 j .Lio_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831/*
832 * External interrupt handler routine
833 */
Jan Glauber144d6342011-07-24 10:48:19 +0200834ENTRY(ext_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200835 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100836 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100837 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100838 lg %r12,__LC_CURRENT
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200839 larl %r13,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100840 lmg %r8,%r9,__LC_EXT_OLD_PSW
Martin Schwidefsky2acb94f2015-06-22 17:28:14 +0200841 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100842 stmg %r0,%r7,__PT_R0(%r11)
843 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
844 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200845 lghi %r1,__LC_EXT_PARAMS2
846 mvc __PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
847 mvc __PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
848 mvc __PT_INT_PARM_LONG(8,%r11),0(%r1)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200849 xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
Heiko Carstensdb7e0072015-08-15 11:42:21 +0200850 TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ
851 jo .Lio_restore
Heiko Carstens1f194a42006-07-03 00:24:46 -0700852 TRACE_IRQS_OFF
Michael Holzheu0de9db32012-05-09 16:27:35 +0200853 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100854 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +0200855 lghi %r3,EXT_INTERRUPT
856 brasl %r14,do_IRQ
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100857 j .Lio_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400859/*
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100860 * Load idle PSW. The second "half" of this function is in .Lcleanup_idle.
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400861 */
862ENTRY(psw_idle)
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200863 stg %r3,__SF_EMPTY(%r15)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100864 larl %r1,.Lpsw_idle_lpsw+4
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400865 stg %r1,__SF_EMPTY+8(%r15)
Martin Schwidefsky72d38b12015-09-18 16:41:36 +0200866#ifdef CONFIG_SMP
867 larl %r1,smp_cpu_mtid
868 llgf %r1,0(%r1)
869 ltgr %r1,%r1
870 jz .Lpsw_idle_stcctm
871 .insn rsy,0xeb0000000017,%r1,5,__SF_EMPTY+16(%r15)
872.Lpsw_idle_stcctm:
873#endif
Martin Schwidefsky419123f2015-11-19 11:09:45 +0100874 oi __LC_CPU_FLAGS+7,_CIF_ENABLED_WAIT
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200875 STCK __CLOCK_IDLE_ENTER(%r2)
876 stpt __TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100877.Lpsw_idle_lpsw:
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400878 lpswe __SF_EMPTY(%r15)
879 br %r14
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100880.Lpsw_idle_end:
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400881
Hendrik Bruecknerb5510d92015-09-29 10:04:41 +0200882/*
883 * Store floating-point controls and floating-point or vector register
884 * depending whether the vector facility is available. A critical section
885 * cleanup assures that the registers are stored even if interrupted for
886 * some other work. The CIF_FPU flag is set to trigger a lazy restore
887 * of the register contents at return from io or a system call.
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200888 */
889ENTRY(save_fpu_regs)
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200890 lg %r2,__LC_CURRENT
891 aghi %r2,__TASK_thread
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200892 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200893 bor %r14
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200894 stfpc __THREAD_FPU_fpc(%r2)
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200895 lg %r3,__THREAD_FPU_regs(%r2)
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200896 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200897 jz .Lsave_fpu_regs_fp # no -> store FP regs
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200898 VSTM %v0,%v15,0,%r3 # vstm 0,15,0(3)
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200899 VSTM %v16,%v31,256,%r3 # vstm 16,31,256(3)
900 j .Lsave_fpu_regs_done # -> set CIF_FPU flag
901.Lsave_fpu_regs_fp:
902 std 0,0(%r3)
903 std 1,8(%r3)
904 std 2,16(%r3)
905 std 3,24(%r3)
906 std 4,32(%r3)
907 std 5,40(%r3)
908 std 6,48(%r3)
909 std 7,56(%r3)
910 std 8,64(%r3)
911 std 9,72(%r3)
912 std 10,80(%r3)
913 std 11,88(%r3)
914 std 12,96(%r3)
915 std 13,104(%r3)
916 std 14,112(%r3)
917 std 15,120(%r3)
918.Lsave_fpu_regs_done:
919 oi __LC_CPU_FLAGS+7,_CIF_FPU
920 br %r14
921.Lsave_fpu_regs_end:
Al Viro711f5df2016-01-12 13:30:03 -0500922EXPORT_SYMBOL(save_fpu_regs)
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200923
Hendrik Bruecknerb5510d92015-09-29 10:04:41 +0200924/*
925 * Load floating-point controls and floating-point or vector registers.
926 * A critical section cleanup assures that the register contents are
927 * loaded even if interrupted for some other work.
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200928 *
929 * There are special calling conventions to fit into sysc and io return work:
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200930 * %r15: <kernel stack>
931 * The function requires:
Hendrik Bruecknerb5510d92015-09-29 10:04:41 +0200932 * %r4
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200933 */
934load_fpu_regs:
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200935 lg %r4,__LC_CURRENT
936 aghi %r4,__TASK_thread
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200937 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200938 bnor %r14
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200939 lfpc __THREAD_FPU_fpc(%r4)
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200940 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +0200941 lg %r4,__THREAD_FPU_regs(%r4) # %r4 <- reg save area
Hendrik Bruecknerb5510d92015-09-29 10:04:41 +0200942 jz .Lload_fpu_regs_fp # -> no VX, load FP regs
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200943 VLM %v0,%v15,0,%r4
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200944 VLM %v16,%v31,256,%r4
945 j .Lload_fpu_regs_done
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200946.Lload_fpu_regs_fp:
947 ld 0,0(%r4)
948 ld 1,8(%r4)
949 ld 2,16(%r4)
950 ld 3,24(%r4)
951 ld 4,32(%r4)
952 ld 5,40(%r4)
953 ld 6,48(%r4)
954 ld 7,56(%r4)
955 ld 8,64(%r4)
956 ld 9,72(%r4)
957 ld 10,80(%r4)
958 ld 11,88(%r4)
959 ld 12,96(%r4)
960 ld 13,104(%r4)
961 ld 14,112(%r4)
962 ld 15,120(%r4)
963.Lload_fpu_regs_done:
964 ni __LC_CPU_FLAGS+7,255-_CIF_FPU
965 br %r14
966.Lload_fpu_regs_end:
967
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100968.L__critical_end:
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970/*
971 * Machine check handler routines
972 */
Jan Glauber144d6342011-07-24 10:48:19 +0200973ENTRY(mcck_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200974 STCK __LC_MCCK_CLOCK
Martin Schwidefsky3037a522017-10-12 13:24:48 +0200975 la %r1,4095 # validate r1
976 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # validate cpu timer
977 sckc __LC_CLOCK_COMPARATOR # validate comparator
978 lam %a0,%a15,__LC_AREGS_SAVE_AREA-4095(%r1) # validate acrs
979 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# validate gprs
Heiko Carstensd5c352c2016-11-08 11:08:26 +0100980 lg %r12,__LC_CURRENT
Hendrik Brueckner9977e882015-06-10 12:53:42 +0200981 larl %r13,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100982 lmg %r8,%r9,__LC_MCK_OLD_PSW
Hendrik Brueckner83abeff2015-10-01 17:02:48 +0200983 TSTMSK __LC_MCCK_CODE,MCCK_CODE_SYSTEM_DAMAGE
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +0100984 jo .Lmcck_panic # yes -> rest of mcck code invalid
Martin Schwidefsky3037a522017-10-12 13:24:48 +0200985 TSTMSK __LC_MCCK_CODE,MCCK_CODE_CR_VALID
986 jno .Lmcck_panic # control registers invalid -> panic
987 la %r14,4095
988 lctlg %c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r14) # validate ctl regs
989 ptlb
Vasily Gorbik2a2d7bef2017-10-27 12:44:48 +0200990 lg %r11,__LC_MCESAD-4095(%r14) # extended machine check save area
Martin Schwidefsky3037a522017-10-12 13:24:48 +0200991 nill %r11,0xfc00 # MCESA_ORIGIN_MASK
992 TSTMSK __LC_CREGS_SAVE_AREA+16-4095(%r14),CR2_GUARDED_STORAGE
993 jno 0f
994 TSTMSK __LC_MCCK_CODE,MCCK_CODE_GS_VALID
995 jno 0f
996 .insn rxy,0xe3000000004d,0,__MCESA_GS_SAVE_AREA(%r11) # LGSC
9970: l %r14,__LC_FP_CREG_SAVE_AREA-4095(%r14)
998 TSTMSK __LC_MCCK_CODE,MCCK_CODE_FC_VALID
999 jo 0f
1000 sr %r14,%r14
10010: sfpc %r14
1002 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
1003 jo 0f
1004 lghi %r14,__LC_FPREGS_SAVE_AREA
1005 ld %f0,0(%r14)
1006 ld %f1,8(%r14)
1007 ld %f2,16(%r14)
1008 ld %f3,24(%r14)
1009 ld %f4,32(%r14)
1010 ld %f5,40(%r14)
1011 ld %f6,48(%r14)
1012 ld %f7,56(%r14)
1013 ld %f8,64(%r14)
1014 ld %f9,72(%r14)
1015 ld %f10,80(%r14)
1016 ld %f11,88(%r14)
1017 ld %f12,96(%r14)
1018 ld %f13,104(%r14)
1019 ld %f14,112(%r14)
1020 ld %f15,120(%r14)
1021 j 1f
10220: VLM %v0,%v15,0,%r11
1023 VLM %v16,%v31,256,%r11
10241: lghi %r14,__LC_CPU_TIMER_SAVE_AREA
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001025 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Hendrik Brueckner83abeff2015-10-01 17:02:48 +02001026 TSTMSK __LC_MCCK_CODE,MCCK_CODE_CPU_TIMER_VALID
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001027 jo 3f
Martin Schwidefsky63b12242006-06-29 14:58:05 +02001028 la %r14,__LC_SYNC_ENTER_TIMER
1029 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
1030 jl 0f
1031 la %r14,__LC_ASYNC_ENTER_TIMER
10320: clc 0(8,%r14),__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001033 jl 1f
Martin Schwidefsky63b12242006-06-29 14:58:05 +02001034 la %r14,__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +010010351: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
1036 jl 2f
Martin Schwidefsky63b12242006-06-29 14:58:05 +02001037 la %r14,__LC_LAST_UPDATE_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +010010382: spt 0(%r14)
Martin Schwidefsky63779812010-05-17 10:00:03 +02001039 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefsky3037a522017-10-12 13:24:48 +020010403: TSTMSK __LC_MCCK_CODE,MCCK_CODE_PSW_MWP_VALID
1041 jno .Lmcck_panic
1042 tmhh %r8,0x0001 # interrupting from user ?
1043 jnz 4f
1044 TSTMSK __LC_MCCK_CODE,MCCK_CODE_PSW_IA_VALID
1045 jno .Lmcck_panic
10464: SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_MCCK_ENTER_TIMER
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001047.Lmcck_skip:
Martin Schwidefsky6551fbd2013-02-28 16:28:41 +01001048 lghi %r14,__LC_GPREGS_SAVE_AREA+64
1049 stmg %r0,%r7,__PT_R0(%r11)
1050 mvc __PT_R8(64,%r11),0(%r14)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001051 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +02001052 xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001053 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
1054 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstens77fa2242005-06-25 14:55:30 -07001055 brasl %r14,s390_do_machine_check
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001056 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001057 jno .Lmcck_return
Heiko Carstens77fa2242005-06-25 14:55:30 -07001058 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001059 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
1060 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
1061 la %r11,STACK_FRAME_OVERHEAD(%r1)
Heiko Carstens77fa2242005-06-25 14:55:30 -07001062 lgr %r15,%r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001063 ssm __LC_PGM_NEW_PSW # turn dat on, keep irqs off
Hendrik Brueckner83abeff2015-10-01 17:02:48 +02001064 TSTMSK __LC_CPU_FLAGS,_CIF_MCCK_PENDING
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001065 jno .Lmcck_return
Heiko Carstens1f194a42006-07-03 00:24:46 -07001066 TRACE_IRQS_OFF
Heiko Carstens77fa2242005-06-25 14:55:30 -07001067 brasl %r14,s390_handle_mcck
Heiko Carstens1f194a42006-07-03 00:24:46 -07001068 TRACE_IRQS_ON
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001069.Lmcck_return:
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001070 lg %r14,__LC_VDSO_PER_CPU
1071 lmg %r0,%r10,__PT_R0(%r11)
1072 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
Martin Schwidefsky63b12242006-06-29 14:58:05 +02001073 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
1074 jno 0f
1075 stpt __LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001076 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
10770: lmg %r11,%r15,__PT_R11(%r11)
1078 lpswe __LC_RETURN_MCCK_PSW
1079
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001080.Lmcck_panic:
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001081 lg %r15,__LC_PANIC_STACK
Martin Schwidefskyce4dda32016-12-02 13:29:22 +01001082 la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001083 j .Lmcck_skip
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001085#
1086# PSW restart interrupt handler
1087#
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001088ENTRY(restart_int_handler)
Christian Borntraegere22cf8c2015-10-06 18:06:15 +02001089 TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
1090 jz 0f
1091 .insn s,0xb2800000,__LC_LPP
10920: stg %r15,__LC_SAVE_AREA_RESTART
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001093 lg %r15,__LC_RESTART_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001094 aghi %r15,-__PT_SIZE # create pt_regs on stack
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001095 xc 0(__PT_SIZE,%r15),0(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001096 stmg %r0,%r14,__PT_R0(%r15)
1097 mvc __PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
1098 mvc __PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001099 aghi %r15,-STACK_FRAME_OVERHEAD # create stack frame on stack
1100 xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
Heiko Carstensfbe76562012-06-05 09:59:52 +02001101 lg %r1,__LC_RESTART_FN # load fn, parm & source cpu
1102 lg %r2,__LC_RESTART_DATA
1103 lg %r3,__LC_RESTART_SOURCE
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001104 ltgr %r3,%r3 # test source cpu address
1105 jm 1f # negative -> skip source stop
Heiko Carstenseb546192012-06-04 15:05:43 +020011060: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001107 brc 10,0b # wait for status stored
11081: basr %r14,%r1 # call function
1109 stap __SF_EMPTY(%r15) # store cpu address
1110 llgh %r3,__SF_EMPTY(%r15)
Heiko Carstenseb546192012-06-04 15:05:43 +020011112: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001112 brc 2,2b
11133: j 3b
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001114
Martin Schwidefsky860dba42011-01-05 12:47:25 +01001115 .section .kprobes.text, "ax"
1116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117#ifdef CONFIG_CHECK_STACK
1118/*
1119 * The synchronous or the asynchronous stack overflowed. We are dead.
1120 * No need to properly save the registers, we are going to panic anyway.
1121 * Setup a pt_regs so that show_trace can provide a good call trace.
1122 */
1123stack_overflow:
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02001124 lg %r15,__LC_PANIC_STACK # change to panic stack
1125 la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001126 stmg %r0,%r7,__PT_R0(%r11)
1127 stmg %r8,%r9,__PT_PSW(%r11)
1128 mvc __PT_R8(64,%r11),0(%r14)
1129 stg %r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001130 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
1131 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 jg kernel_stack_overflow
1133#endif
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135cleanup_critical:
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02001136#if IS_ENABLED(CONFIG_KVM)
1137 clg %r9,BASED(.Lcleanup_table_sie) # .Lsie_gmap
1138 jl 0f
1139 clg %r9,BASED(.Lcleanup_table_sie+8)# .Lsie_done
1140 jl .Lcleanup_sie
1141#endif
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001142 clg %r9,BASED(.Lcleanup_table) # system_call
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 jl 0f
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001144 clg %r9,BASED(.Lcleanup_table+8) # .Lsysc_do_svc
1145 jl .Lcleanup_system_call
1146 clg %r9,BASED(.Lcleanup_table+16) # .Lsysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 jl 0f
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001148 clg %r9,BASED(.Lcleanup_table+24) # .Lsysc_restore
1149 jl .Lcleanup_sysc_tif
1150 clg %r9,BASED(.Lcleanup_table+32) # .Lsysc_done
1151 jl .Lcleanup_sysc_restore
1152 clg %r9,BASED(.Lcleanup_table+40) # .Lio_tif
Martin Schwidefsky63b12242006-06-29 14:58:05 +02001153 jl 0f
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001154 clg %r9,BASED(.Lcleanup_table+48) # .Lio_restore
1155 jl .Lcleanup_io_tif
1156 clg %r9,BASED(.Lcleanup_table+56) # .Lio_done
1157 jl .Lcleanup_io_restore
1158 clg %r9,BASED(.Lcleanup_table+64) # psw_idle
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001159 jl 0f
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001160 clg %r9,BASED(.Lcleanup_table+72) # .Lpsw_idle_end
1161 jl .Lcleanup_idle
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001162 clg %r9,BASED(.Lcleanup_table+80) # save_fpu_regs
1163 jl 0f
1164 clg %r9,BASED(.Lcleanup_table+88) # .Lsave_fpu_regs_end
1165 jl .Lcleanup_save_fpu_regs
1166 clg %r9,BASED(.Lcleanup_table+96) # load_fpu_regs
1167 jl 0f
1168 clg %r9,BASED(.Lcleanup_table+104) # .Lload_fpu_regs_end
1169 jl .Lcleanup_load_fpu_regs
Martin Schwidefskyc5328902011-12-27 11:27:15 +010011700: br %r14
1171
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02001172 .align 8
1173.Lcleanup_table:
1174 .quad system_call
1175 .quad .Lsysc_do_svc
1176 .quad .Lsysc_tif
1177 .quad .Lsysc_restore
1178 .quad .Lsysc_done
1179 .quad .Lio_tif
1180 .quad .Lio_restore
1181 .quad .Lio_done
1182 .quad psw_idle
1183 .quad .Lpsw_idle_end
1184 .quad save_fpu_regs
1185 .quad .Lsave_fpu_regs_end
1186 .quad load_fpu_regs
1187 .quad .Lload_fpu_regs_end
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02001188
1189#if IS_ENABLED(CONFIG_KVM)
1190.Lcleanup_table_sie:
1191 .quad .Lsie_gmap
1192 .quad .Lsie_done
1193
1194.Lcleanup_sie:
QingFeng Haoc9295002017-06-07 11:30:42 +02001195 cghi %r11,__LC_SAVE_AREA_ASYNC #Is this in normal interrupt?
1196 je 1f
1197 slg %r9,BASED(.Lsie_crit_mcck_start)
1198 clg %r9,BASED(.Lsie_crit_mcck_length)
1199 jh 1f
1200 oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
12011: lg %r9,__SF_EMPTY(%r15) # get control block pointer
Christian Borntraegere22cf8c2015-10-06 18:06:15 +02001202 ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02001203 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
1204 larl %r9,sie_exit # skip forward to sie_exit
1205 br %r14
1206#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001208.Lcleanup_system_call:
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001209 # check if stpt has been executed
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001210 clg %r9,BASED(.Lcleanup_system_call_insn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 jh 0f
1212 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001213 cghi %r11,__LC_SAVE_AREA_ASYNC
Martin Schwidefsky63779812010-05-17 10:00:03 +02001214 je 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001215 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
12160: # check if stmg has been executed
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001217 clg %r9,BASED(.Lcleanup_system_call_insn+8)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 jh 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001219 mvc __LC_SAVE_AREA_SYNC(64),0(%r11)
12200: # check if base register setup + TIF bit load has been done
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001221 clg %r9,BASED(.Lcleanup_system_call_insn+16)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001222 jhe 0f
Martin Schwidefsky34525e12017-01-25 12:54:17 +01001223 # set up saved register r12 task struct pointer
1224 stg %r12,32(%r11)
1225 # set up saved register r13 __TASK_thread offset
1226 mvc 40(8,%r11),BASED(.Lcleanup_system_call_const)
Martin Schwidefskyc5328902011-12-27 11:27:15 +010012270: # check if the user time update has been done
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001228 clg %r9,BASED(.Lcleanup_system_call_insn+24)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001229 jh 0f
1230 lg %r15,__LC_EXIT_TIMER
1231 slg %r15,__LC_SYNC_ENTER_TIMER
1232 alg %r15,__LC_USER_TIMER
1233 stg %r15,__LC_USER_TIMER
12340: # check if the system time update has been done
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001235 clg %r9,BASED(.Lcleanup_system_call_insn+32)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001236 jh 0f
1237 lg %r15,__LC_LAST_UPDATE_TIMER
1238 slg %r15,__LC_EXIT_TIMER
1239 alg %r15,__LC_SYSTEM_TIMER
1240 stg %r15,__LC_SYSTEM_TIMER
12410: # update accounting time stamp
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky34525e12017-01-25 12:54:17 +01001243 # set up saved register r11
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001244 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02001245 la %r9,STACK_FRAME_OVERHEAD(%r15)
1246 stg %r9,24(%r11) # r11 pt_regs pointer
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001247 # fill pt_regs
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02001248 mvc __PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
1249 stmg %r0,%r7,__PT_R0(%r9)
1250 mvc __PT_PSW(16,%r9),__LC_SVC_OLD_PSW
1251 mvc __PT_INT_CODE(4,%r9),__LC_SVC_ILC
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +02001252 xc __PT_FLAGS(8,%r9),__PT_FLAGS(%r9)
1253 mvi __PT_FLAGS+7(%r9),_PIF_SYSCALL
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001254 # setup saved register r15
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001255 stg %r15,56(%r11) # r15 stack pointer
1256 # set new psw address and exit
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001257 larl %r9,.Lsysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 br %r14
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001259.Lcleanup_system_call_insn:
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001260 .quad system_call
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001261 .quad .Lsysc_stmg
1262 .quad .Lsysc_per
Martin Schwidefskya359bb12015-06-22 17:27:48 +02001263 .quad .Lsysc_vtime+36
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001264 .quad .Lsysc_vtime+42
Martin Schwidefsky34525e12017-01-25 12:54:17 +01001265.Lcleanup_system_call_const:
1266 .quad __TASK_thread
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001268.Lcleanup_sysc_tif:
1269 larl %r9,.Lsysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 br %r14
1271
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001272.Lcleanup_sysc_restore:
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001273 # check if stpt has been executed
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001274 clg %r9,BASED(.Lcleanup_sysc_restore_insn)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001275 jh 0f
1276 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
1277 cghi %r11,__LC_SAVE_AREA_ASYNC
Martin Schwidefsky63779812010-05-17 10:00:03 +02001278 je 0f
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001279 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
12800: clg %r9,BASED(.Lcleanup_sysc_restore_insn+8)
1281 je 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001282 lg %r9,24(%r11) # get saved pointer to pt_regs
1283 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
1284 mvc 0(64,%r11),__PT_R8(%r9)
1285 lmg %r0,%r7,__PT_R0(%r9)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +020012861: lmg %r8,%r9,__LC_RETURN_PSW
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 br %r14
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001288.Lcleanup_sysc_restore_insn:
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001289 .quad .Lsysc_exit_timer
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001290 .quad .Lsysc_done - 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001292.Lcleanup_io_tif:
1293 larl %r9,.Lio_tif
Martin Schwidefsky176b1802010-04-09 13:43:00 +02001294 br %r14
1295
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001296.Lcleanup_io_restore:
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001297 # check if stpt has been executed
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001298 clg %r9,BASED(.Lcleanup_io_restore_insn)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001299 jh 0f
1300 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
13010: clg %r9,BASED(.Lcleanup_io_restore_insn+8)
1302 je 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001303 lg %r9,24(%r11) # get saved r11 pointer to pt_regs
1304 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001305 mvc 0(64,%r11),__PT_R8(%r9)
1306 lmg %r0,%r7,__PT_R0(%r9)
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +020013071: lmg %r8,%r9,__LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001308 br %r14
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001309.Lcleanup_io_restore_insn:
Martin Schwidefsky07a63cb2017-05-02 13:36:00 +02001310 .quad .Lio_exit_timer
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001311 .quad .Lio_done - 4
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001312
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001313.Lcleanup_idle:
Martin Schwidefsky419123f2015-11-19 11:09:45 +01001314 ni __LC_CPU_FLAGS+7,255-_CIF_ENABLED_WAIT
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001315 # copy interrupt clock & cpu timer
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001316 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
1317 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001318 cghi %r11,__LC_SAVE_AREA_ASYNC
1319 je 0f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001320 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
1321 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -040013220: # check if stck & stpt have been executed
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001323 clg %r9,BASED(.Lcleanup_idle_insn)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001324 jhe 1f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001325 mvc __CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
1326 mvc __TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
Martin Schwidefsky72d38b12015-09-18 16:41:36 +020013271: # calculate idle cycles
1328#ifdef CONFIG_SMP
1329 clg %r9,BASED(.Lcleanup_idle_insn)
1330 jl 3f
1331 larl %r1,smp_cpu_mtid
1332 llgf %r1,0(%r1)
1333 ltgr %r1,%r1
1334 jz 3f
1335 .insn rsy,0xeb0000000017,%r1,5,__SF_EMPTY+80(%r15)
1336 larl %r3,mt_cycles
1337 ag %r3,__LC_PERCPU_OFFSET
1338 la %r4,__SF_EMPTY+16(%r15)
13392: lg %r0,0(%r3)
1340 slg %r0,0(%r4)
1341 alg %r0,64(%r4)
1342 stg %r0,0(%r3)
1343 la %r3,8(%r3)
1344 la %r4,8(%r4)
1345 brct %r1,2b
1346#endif
13473: # account system time going idle
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001348 lg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001349 alg %r9,__CLOCK_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001350 slg %r9,__LC_LAST_UPDATE_CLOCK
1351 stg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001352 mvc __LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001353 lg %r9,__LC_SYSTEM_TIMER
1354 alg %r9,__LC_LAST_UPDATE_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001355 slg %r9,__TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001356 stg %r9,__LC_SYSTEM_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02001357 mvc __LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001358 # prepare return psw
Martin Schwidefsky0587d402013-08-23 14:45:58 +02001359 nihh %r8,0xfcfd # clear irq & wait state bits
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001360 lg %r9,48(%r11) # return from psw_idle
1361 br %r14
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001362.Lcleanup_idle_insn:
1363 .quad .Lpsw_idle_lpsw
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04001364
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001365.Lcleanup_save_fpu_regs:
Martin Schwidefskye370e472016-03-10 09:52:55 +01001366 larl %r9,save_fpu_regs
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001367 br %r14
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001368
1369.Lcleanup_load_fpu_regs:
Martin Schwidefskye370e472016-03-10 09:52:55 +01001370 larl %r9,load_fpu_regs
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001371 br %r14
Hendrik Brueckner9977e882015-06-10 12:53:42 +02001372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373/*
1374 * Integer constants
1375 */
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001376 .align 8
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377.Lcritical_start:
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001378 .quad .L__critical_start
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001379.Lcritical_length:
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001380 .quad .L__critical_end - .L__critical_start
Heiko Carstens61aa4882013-11-01 10:08:20 +01001381#if IS_ENABLED(CONFIG_KVM)
Martin Schwidefskyd0fc4102015-06-22 17:26:40 +02001382.Lsie_critical_start:
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001383 .quad .Lsie_gmap
Martin Schwidefsky7c470532013-05-17 14:41:37 +02001384.Lsie_critical_length:
Martin Schwidefsky86ed42f2014-12-03 17:00:08 +01001385 .quad .Lsie_done - .Lsie_gmap
QingFeng Haoc9295002017-06-07 11:30:42 +02001386.Lsie_crit_mcck_start:
1387 .quad .Lsie_entry
1388.Lsie_crit_mcck_length:
1389 .quad .Lsie_skip - .Lsie_entry
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001390#endif
1391
Heiko Carstensa876cb32015-02-13 14:44:29 +01001392 .section .rodata, "a"
1393#define SYSCALL(esame,emu) .long esame
Heiko Carstens9bf12262009-06-12 10:26:47 +02001394 .globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395sys_call_table:
1396#include "syscalls.S"
1397#undef SYSCALL
1398
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001399#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Heiko Carstensa876cb32015-02-13 14:44:29 +01001401#define SYSCALL(esame,emu) .long emu
Martin Schwidefsky61649882013-04-24 12:58:39 +02001402 .globl sys_call_table_emu
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403sys_call_table_emu:
1404#include "syscalls.S"
1405#undef SYSCALL
1406#endif