blob: 14f25798b001ca770ccb8ae63099ce9f86f988c8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003 * Copyright IBM Corp. 1999
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Author(s): Hartmut Penner (hp@de.ibm.com)
5 * Ulrich Weigand (uweigand@de.ibm.com)
6 *
7 * Derived from "arch/i386/mm/fault.c"
8 * Copyright (C) 1995 Linus Torvalds
9 */
10
Heiko Carstens052ff462011-01-05 12:47:28 +010011#include <linux/kernel_stat.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020012#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/signal.h>
14#include <linux/sched.h>
Ingo Molnarb17b0152017-02-08 18:51:35 +010015#include <linux/sched/debug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/string.h>
19#include <linux/types.h>
20#include <linux/ptrace.h>
21#include <linux/mman.h>
22#include <linux/mm.h>
Heiko Carstens77575912009-06-12 10:26:25 +020023#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/smp.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070025#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/console.h>
Paul Gortmakerdcc096c2016-09-19 17:54:56 -040028#include <linux/extable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/hardirq.h>
Michael Grundy4ba069b2006-09-20 15:58:39 +020030#include <linux/kprobes.h>
Martin Schwidefskybe5ec362007-04-27 16:01:44 +020031#include <linux/uaccess.h>
Gerald Schaefer53492b12008-04-30 13:38:46 +020032#include <linux/hugetlb.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010033#include <asm/asm-offsets.h>
Martin Schwidefsky1ec27722015-08-20 17:28:44 +020034#include <asm/diag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/pgtable.h>
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010036#include <asm/gmap.h>
Heiko Carstensd7b250e2011-05-26 09:48:24 +020037#include <asm/irq.h>
Martin Schwidefsky6252d702008-02-09 18:24:37 +010038#include <asm/mmu_context.h>
David Howellsa0616cd2012-03-28 18:30:02 +010039#include <asm/facility.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020040#include "../kernel/entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define __FAIL_ADDR_MASK -4096L
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define __SUBCODE_MASK 0x0600
44#define __PF_RES_FIELD 0x8000000000000000ULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Martin Schwidefsky50d72802009-12-07 12:51:45 +010046#define VM_FAULT_BADCONTEXT 0x010000
47#define VM_FAULT_BADMAP 0x020000
48#define VM_FAULT_BADACCESS 0x040000
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010049#define VM_FAULT_SIGNAL 0x080000
Dominik Dingel24eb3a82013-06-17 16:25:18 +020050#define VM_FAULT_PFAULT 0x100000
Martin Schwidefsky50d72802009-12-07 12:51:45 +010051
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010052static unsigned long store_indication __read_mostly;
Martin Schwidefsky92f842e2010-10-25 16:10:13 +020053
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010054static int __init fault_init(void)
Martin Schwidefsky92f842e2010-10-25 16:10:13 +020055{
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010056 if (test_facility(75))
Martin Schwidefsky92f842e2010-10-25 16:10:13 +020057 store_indication = 0xc00;
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010058 return 0;
Martin Schwidefsky92f842e2010-10-25 16:10:13 +020059}
Heiko Carstensa4f32bd2012-10-30 14:49:37 +010060early_initcall(fault_init);
Martin Schwidefsky92f842e2010-10-25 16:10:13 +020061
Martin Schwidefsky7ecb3442009-12-07 12:51:44 +010062static inline int notify_page_fault(struct pt_regs *regs)
Martin Schwidefsky10c10312007-04-27 16:01:43 +020063{
Christoph Hellwig33464e32007-05-04 18:47:46 +020064 int ret = 0;
65
66 /* kprobe_running() needs smp_processor_id() */
Heiko Carstens22e0a042010-02-26 22:37:45 +010067 if (kprobes_built_in() && !user_mode(regs)) {
Christoph Hellwig33464e32007-05-04 18:47:46 +020068 preempt_disable();
69 if (kprobe_running() && kprobe_fault_handler(regs, 14))
70 ret = 1;
71 preempt_enable();
72 }
Christoph Hellwig33464e32007-05-04 18:47:46 +020073 return ret;
Michael Grundy4ba069b2006-09-20 15:58:39 +020074}
Michael Grundy4ba069b2006-09-20 15:58:39 +020075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * Unlock any spinlocks which will prevent us from getting the
Kirill Korotaevcefc8be2007-02-10 01:46:18 -080079 * message out.
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
81void bust_spinlocks(int yes)
82{
83 if (yes) {
84 oops_in_progress = 1;
85 } else {
86 int loglevel_save = console_loglevel;
87 console_unblank();
88 oops_in_progress = 0;
89 /*
90 * OK, the message is on the console. Now we call printk()
91 * without oops_in_progress set so that printk will give klogd
92 * a poke. Hold onto your hats...
93 */
94 console_loglevel = 15;
95 printk(" ");
96 console_loglevel = loglevel_save;
97 }
98}
99
100/*
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100101 * Returns the address space associated with the fault.
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100102 * Returns 0 for kernel space and 1 for user space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 */
Heiko Carstens457f2182014-03-21 10:42:25 +0100104static inline int user_space_fault(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Heiko Carstens457f2182014-03-21 10:42:25 +0100106 unsigned long trans_exc_code;
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 /*
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100109 * The lowest two bits of the translation exception
110 * identification indicate which paging table was used.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 */
Heiko Carstens457f2182014-03-21 10:42:25 +0100112 trans_exc_code = regs->int_parm_long & 3;
113 if (trans_exc_code == 3) /* home space -> kernel */
114 return 0;
115 if (user_mode(regs))
116 return 1;
117 if (trans_exc_code == 2) /* secondary space -> set_fs */
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100118 return current->thread.mm_segment.ar4;
Heiko Carstens457f2182014-03-21 10:42:25 +0100119 if (current->flags & PF_VCPU)
120 return 1;
121 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Heiko Carstens3b7df342014-04-07 10:20:40 +0200124static int bad_address(void *p)
125{
126 unsigned long dummy;
127
128 return probe_kernel_address((unsigned long *)p, dummy);
129}
130
Heiko Carstens3b7df342014-04-07 10:20:40 +0200131static void dump_pagetable(unsigned long asce, unsigned long address)
132{
Heiko Carstensfe7b2742017-05-22 13:16:00 +0200133 unsigned long *table = __va(asce & _ASCE_ORIGIN);
Heiko Carstens3b7df342014-04-07 10:20:40 +0200134
135 pr_alert("AS:%016lx ", asce);
136 switch (asce & _ASCE_TYPE_MASK) {
137 case _ASCE_TYPE_REGION1:
138 table = table + ((address >> 53) & 0x7ff);
139 if (bad_address(table))
140 goto bad;
141 pr_cont("R1:%016lx ", *table);
142 if (*table & _REGION_ENTRY_INVALID)
143 goto out;
144 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
145 /* fallthrough */
146 case _ASCE_TYPE_REGION2:
147 table = table + ((address >> 42) & 0x7ff);
148 if (bad_address(table))
149 goto bad;
150 pr_cont("R2:%016lx ", *table);
151 if (*table & _REGION_ENTRY_INVALID)
152 goto out;
153 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
154 /* fallthrough */
155 case _ASCE_TYPE_REGION3:
156 table = table + ((address >> 31) & 0x7ff);
157 if (bad_address(table))
158 goto bad;
159 pr_cont("R3:%016lx ", *table);
160 if (*table & (_REGION_ENTRY_INVALID | _REGION3_ENTRY_LARGE))
161 goto out;
162 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
163 /* fallthrough */
164 case _ASCE_TYPE_SEGMENT:
165 table = table + ((address >> 20) & 0x7ff);
166 if (bad_address(table))
167 goto bad;
Joe Perches91c08372015-01-05 04:29:18 -0800168 pr_cont("S:%016lx ", *table);
Heiko Carstens3b7df342014-04-07 10:20:40 +0200169 if (*table & (_SEGMENT_ENTRY_INVALID | _SEGMENT_ENTRY_LARGE))
170 goto out;
171 table = (unsigned long *)(*table & _SEGMENT_ENTRY_ORIGIN);
172 }
173 table = table + ((address >> 12) & 0xff);
174 if (bad_address(table))
175 goto bad;
176 pr_cont("P:%016lx ", *table);
177out:
178 pr_cont("\n");
179 return;
180bad:
181 pr_cont("BAD\n");
182}
183
Heiko Carstens3b7df342014-04-07 10:20:40 +0200184static void dump_fault_info(struct pt_regs *regs)
185{
186 unsigned long asce;
187
Heiko Carstens5d7ecce2016-02-24 14:27:46 +0100188 pr_alert("Failing address: %016lx TEID: %016lx\n",
189 regs->int_parm_long & __FAIL_ADDR_MASK, regs->int_parm_long);
Heiko Carstens3b7df342014-04-07 10:20:40 +0200190 pr_alert("Fault in ");
191 switch (regs->int_parm_long & 3) {
192 case 3:
193 pr_cont("home space ");
194 break;
195 case 2:
196 pr_cont("secondary space ");
197 break;
198 case 1:
199 pr_cont("access register ");
200 break;
201 case 0:
202 pr_cont("primary space ");
203 break;
204 }
205 pr_cont("mode while using ");
206 if (!user_space_fault(regs)) {
207 asce = S390_lowcore.kernel_asce;
208 pr_cont("kernel ");
209 }
210#ifdef CONFIG_PGSTE
211 else if ((current->flags & PF_VCPU) && S390_lowcore.gmap) {
212 struct gmap *gmap = (struct gmap *)S390_lowcore.gmap;
213 asce = gmap->asce;
214 pr_cont("gmap ");
215 }
216#endif
217 else {
218 asce = S390_lowcore.user_asce;
219 pr_cont("user ");
220 }
221 pr_cont("ASCE.\n");
222 dump_pagetable(asce, regs->int_parm_long & __FAIL_ADDR_MASK);
223}
224
Heiko Carstens5d7ecce2016-02-24 14:27:46 +0100225int show_unhandled_signals = 1;
226
227void report_user_fault(struct pt_regs *regs, long signr, int is_mm_fault)
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200228{
229 if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
230 return;
231 if (!unhandled_signal(current, signr))
232 return;
233 if (!printk_ratelimit())
234 return;
Hendrik Bruecknerdb1177ee2015-01-29 14:38:38 +0100235 printk(KERN_ALERT "User process fault: interruption code %04x ilc:%d ",
Heiko Carstens413d4042014-11-19 13:31:08 +0100236 regs->int_code & 0xffff, regs->int_code >> 17);
Heiko Carstens9cb1cce2016-01-18 13:12:19 +0100237 print_vma_addr(KERN_CONT "in ", regs->psw.addr);
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100238 printk(KERN_CONT "\n");
Heiko Carstens5d7ecce2016-02-24 14:27:46 +0100239 if (is_mm_fault)
240 dump_fault_info(regs);
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200241 show_regs(regs);
242}
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/*
245 * Send SIGSEGV to task. This is an external routine
246 * to keep the stack usage of do_page_fault small.
247 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100248static noinline void do_sigsegv(struct pt_regs *regs, int si_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 struct siginfo si;
251
Heiko Carstens5d7ecce2016-02-24 14:27:46 +0100252 report_user_fault(regs, SIGSEGV, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 si.si_signo = SIGSEGV;
Michal Hockocf0d44d2016-05-23 15:35:51 +0200254 si.si_errno = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 si.si_code = si_code;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100256 si.si_addr = (void __user *)(regs->int_parm_long & __FAIL_ADDR_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 force_sig_info(SIGSEGV, &si, current);
258}
259
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100260static noinline void do_no_context(struct pt_regs *regs)
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200261{
262 const struct exception_table_entry *fixup;
263
264 /* Are we prepared to handle this kernel fault? */
Heiko Carstens9cb1cce2016-01-18 13:12:19 +0100265 fixup = search_exception_tables(regs->psw.addr);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200266 if (fixup) {
Heiko Carstensfecc868a2016-01-18 12:49:44 +0100267 regs->psw.addr = extable_fixup(fixup);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200268 return;
269 }
270
271 /*
272 * Oops. The kernel tried to access some bad page. We'll have to
273 * terminate things with extreme prejudice.
274 */
Heiko Carstens457f2182014-03-21 10:42:25 +0100275 if (!user_space_fault(regs))
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200276 printk(KERN_ALERT "Unable to handle kernel pointer dereference"
Heiko Carstens3b7df342014-04-07 10:20:40 +0200277 " in virtual kernel address space\n");
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200278 else
279 printk(KERN_ALERT "Unable to handle kernel paging request"
Heiko Carstens3b7df342014-04-07 10:20:40 +0200280 " in virtual user address space\n");
Heiko Carstens3b7df342014-04-07 10:20:40 +0200281 dump_fault_info(regs);
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100282 die(regs, "Oops");
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200283 do_exit(SIGKILL);
284}
285
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100286static noinline void do_low_address(struct pt_regs *regs)
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200287{
288 /* Low-address protection hit in kernel mode means
289 NULL pointer write access in kernel mode. */
290 if (regs->psw.mask & PSW_MASK_PSTATE) {
291 /* Low-address protection hit in user mode 'cannot happen'. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100292 die (regs, "Low-address protection");
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200293 do_exit(SIGKILL);
294 }
295
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100296 do_no_context(regs);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200297}
298
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100299static noinline void do_sigbus(struct pt_regs *regs)
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200300{
301 struct task_struct *tsk = current;
Martin Schwidefsky36bf9682010-10-25 16:10:35 +0200302 struct siginfo si;
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200303
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200304 /*
305 * Send a sigbus, regardless of whether we were in kernel
306 * or user mode.
307 */
Martin Schwidefsky36bf9682010-10-25 16:10:35 +0200308 si.si_signo = SIGBUS;
309 si.si_errno = 0;
310 si.si_code = BUS_ADRERR;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100311 si.si_addr = (void __user *)(regs->int_parm_long & __FAIL_ADDR_MASK);
Martin Schwidefsky36bf9682010-10-25 16:10:35 +0200312 force_sig_info(SIGBUS, &si, tsk);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200313}
314
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100315static noinline int signal_return(struct pt_regs *regs)
316{
317 u16 instruction;
318 int rc;
319
320 rc = __get_user(instruction, (u16 __user *) regs->psw.addr);
321 if (rc)
322 return rc;
323 if (instruction == 0x0a77) {
324 set_pt_regs_flag(regs, PIF_SYSCALL);
325 regs->int_code = 0x00040077;
326 return 0;
327 } else if (instruction == 0x0aad) {
328 set_pt_regs_flag(regs, PIF_SYSCALL);
329 regs->int_code = 0x000400ad;
330 return 0;
331 }
332 return -EACCES;
333}
334
335static noinline void do_fault_error(struct pt_regs *regs, int access, int fault)
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100336{
337 int si_code;
338
339 switch (fault) {
340 case VM_FAULT_BADACCESS:
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100341 if (access == VM_EXEC && signal_return(regs) == 0)
342 break;
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100343 case VM_FAULT_BADMAP:
344 /* Bad memory access. Check if it is kernel or user space. */
Heiko Carstens7d256172012-07-27 10:31:12 +0200345 if (user_mode(regs)) {
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100346 /* User mode accesses just cause a SIGSEGV */
347 si_code = (fault == VM_FAULT_BADMAP) ?
348 SEGV_MAPERR : SEGV_ACCERR;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100349 do_sigsegv(regs, si_code);
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100350 break;
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100351 }
352 case VM_FAULT_BADCONTEXT:
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200353 case VM_FAULT_PFAULT:
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100354 do_no_context(regs);
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100355 break;
Heiko Carstensf2c76e32012-07-27 08:54:20 +0200356 case VM_FAULT_SIGNAL:
357 if (!user_mode(regs))
358 do_no_context(regs);
359 break;
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100360 default: /* fault & VM_FAULT_ERROR */
Heiko Carstens99583182011-05-26 09:48:29 +0200361 if (fault & VM_FAULT_OOM) {
Heiko Carstens7d256172012-07-27 10:31:12 +0200362 if (!user_mode(regs))
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100363 do_no_context(regs);
Heiko Carstens99583182011-05-26 09:48:29 +0200364 else
365 pagefault_out_of_memory();
Linus Torvalds33692f22015-01-29 10:51:32 -0800366 } else if (fault & VM_FAULT_SIGSEGV) {
367 /* Kernel mode? Handle exceptions or die */
368 if (!user_mode(regs))
369 do_no_context(regs);
370 else
371 do_sigsegv(regs, SEGV_MAPERR);
Heiko Carstens99583182011-05-26 09:48:29 +0200372 } else if (fault & VM_FAULT_SIGBUS) {
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100373 /* Kernel mode? Handle exceptions or die */
Heiko Carstens7d256172012-07-27 10:31:12 +0200374 if (!user_mode(regs))
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100375 do_no_context(regs);
Martin Schwidefsky36bf9682010-10-25 16:10:35 +0200376 else
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100377 do_sigbus(regs);
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100378 } else
379 BUG();
380 break;
381 }
382}
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*
385 * This routine handles page faults. It determines the address,
386 * and the problem, and then passes it off to one of the appropriate
387 * routines.
388 *
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100389 * interruption code (int_code):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 * 04 Protection -> Write-Protection (suprression)
391 * 10 Segment translation -> Not present (nullification)
392 * 11 Page translation -> Not present (nullification)
393 * 3b Region third trans. -> Not present (nullification)
394 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100395static inline int do_exception(struct pt_regs *regs, int access)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200397#ifdef CONFIG_PGSTE
398 struct gmap *gmap;
399#endif
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200400 struct task_struct *tsk;
401 struct mm_struct *mm;
402 struct vm_area_struct *vma;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100403 unsigned long trans_exc_code;
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200404 unsigned long address;
Heiko Carstens33ce6142011-05-26 09:48:30 +0200405 unsigned int flags;
406 int fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100408 tsk = current;
409 /*
410 * The instruction that caused the program check has
411 * been nullified. Don't signal single step via SIGTRAP.
412 */
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +0200413 clear_pt_regs_flag(regs, PIF_PER_TRAP);
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100414
Martin Schwidefsky7ecb3442009-12-07 12:51:44 +0100415 if (notify_page_fault(regs))
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100416 return 0;
Michael Grundy4ba069b2006-09-20 15:58:39 +0200417
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200418 mm = tsk->mm;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100419 trans_exc_code = regs->int_parm_long;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
422 * Verify that the fault happened in user space, that
423 * we are not in an interrupt and that there is a
424 * user context.
425 */
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100426 fault = VM_FAULT_BADCONTEXT;
David Hildenbrand70ffdb92015-05-11 17:52:11 +0200427 if (unlikely(!user_space_fault(regs) || faulthandler_disabled() || !mm))
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100428 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100430 address = trans_exc_code & __FAIL_ADDR_MASK;
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200431 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
Heiko Carstensf2c76e32012-07-27 08:54:20 +0200432 flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
Johannes Weiner759496b2013-09-12 15:13:39 -0700433 if (user_mode(regs))
434 flags |= FAULT_FLAG_USER;
Heiko Carstens33ce6142011-05-26 09:48:30 +0200435 if (access == VM_WRITE || (trans_exc_code & store_indication) == 0x400)
436 flags |= FAULT_FLAG_WRITE;
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200437 down_read(&mm->mmap_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200439#ifdef CONFIG_PGSTE
Martin Schwidefsky527e30b2014-04-30 16:04:25 +0200440 gmap = (current->flags & PF_VCPU) ?
441 (struct gmap *) S390_lowcore.gmap : NULL;
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200442 if (gmap) {
Martin Schwidefsky527e30b2014-04-30 16:04:25 +0200443 current->thread.gmap_addr = address;
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100444 current->thread.gmap_write_flag = !!(flags & FAULT_FLAG_WRITE);
David Hildenbrand4a494432016-03-08 12:31:52 +0100445 current->thread.gmap_int_code = regs->int_code & 0xffff;
Martin Schwidefsky527e30b2014-04-30 16:04:25 +0200446 address = __gmap_translate(gmap, address);
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200447 if (address == -EFAULT) {
448 fault = VM_FAULT_BADMAP;
449 goto out_up;
450 }
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200451 if (gmap->pfault_enabled)
452 flags |= FAULT_FLAG_RETRY_NOWAIT;
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200453 }
454#endif
455
456retry:
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100457 fault = VM_FAULT_BADMAP;
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100458 vma = find_vma(mm, address);
459 if (!vma)
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100460 goto out_up;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100461
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100462 if (unlikely(vma->vm_start > address)) {
463 if (!(vma->vm_flags & VM_GROWSDOWN))
464 goto out_up;
465 if (expand_stack(vma, address))
466 goto out_up;
467 }
468
469 /*
470 * Ok, we have a good vm_area for this memory access, so
471 * we can handle it..
472 */
473 fault = VM_FAULT_BADACCESS;
Martin Schwidefsky1ab947d2009-12-07 12:51:46 +0100474 if (unlikely(!(vma->vm_flags & access)))
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100475 goto out_up;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Gerald Schaefer53492b12008-04-30 13:38:46 +0200477 if (is_vm_hugetlb_page(vma))
478 address &= HPAGE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 /*
480 * If for any reason at all we couldn't handle the fault,
481 * make sure we exit gracefully rather than endlessly redo
482 * the fault.
483 */
Kirill A. Shutemovdcddffd2016-07-26 15:25:18 -0700484 fault = handle_mm_fault(vma, address, flags);
Heiko Carstensf2c76e32012-07-27 08:54:20 +0200485 /* No reason to continue if interrupted by SIGKILL. */
486 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
487 fault = VM_FAULT_SIGNAL;
488 goto out;
489 }
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100490 if (unlikely(fault & VM_FAULT_ERROR))
491 goto out_up;
492
Heiko Carstens33ce6142011-05-26 09:48:30 +0200493 /*
494 * Major/minor page fault accounting is only done on the
495 * initial attempt. If we go through a retry, it is extremely
496 * likely that the page will be found in page cache at that point.
497 */
498 if (flags & FAULT_FLAG_ALLOW_RETRY) {
499 if (fault & VM_FAULT_MAJOR) {
500 tsk->maj_flt++;
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200501 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
Heiko Carstens33ce6142011-05-26 09:48:30 +0200502 regs, address);
503 } else {
504 tsk->min_flt++;
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +0200505 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
Heiko Carstens33ce6142011-05-26 09:48:30 +0200506 regs, address);
507 }
508 if (fault & VM_FAULT_RETRY) {
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200509#ifdef CONFIG_PGSTE
510 if (gmap && (flags & FAULT_FLAG_RETRY_NOWAIT)) {
511 /* FAULT_FLAG_RETRY_NOWAIT has been set,
512 * mmap_sem has not been released */
513 current->thread.gmap_pfault = 1;
514 fault = VM_FAULT_PFAULT;
515 goto out_up;
516 }
517#endif
Heiko Carstens33ce6142011-05-26 09:48:30 +0200518 /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
519 * of starvation. */
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200520 flags &= ~(FAULT_FLAG_ALLOW_RETRY |
521 FAULT_FLAG_RETRY_NOWAIT);
Shaohua Li45cac652012-10-08 16:32:19 -0700522 flags |= FAULT_FLAG_TRIED;
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200523 down_read(&mm->mmap_sem);
Heiko Carstens33ce6142011-05-26 09:48:30 +0200524 goto retry;
525 }
Heiko Carstensbde69af2009-09-11 10:29:06 +0200526 }
Martin Schwidefsky527e30b2014-04-30 16:04:25 +0200527#ifdef CONFIG_PGSTE
528 if (gmap) {
529 address = __gmap_link(gmap, current->thread.gmap_addr,
530 address);
531 if (address == -EFAULT) {
532 fault = VM_FAULT_BADMAP;
533 goto out_up;
534 }
535 if (address == -ENOMEM) {
536 fault = VM_FAULT_OOM;
537 goto out_up;
538 }
539 }
540#endif
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100541 fault = 0;
542out_up:
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200543 up_read(&mm->mmap_sem);
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100544out:
545 return fault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
Heiko Carstens7a5388d2014-10-22 12:42:38 +0200548void do_protection_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100550 unsigned long trans_exc_code;
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100551 int access, fault;
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100552
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100553 trans_exc_code = regs->int_parm_long;
Martin Schwidefskyf752ac42013-04-16 13:25:06 +0200554 /*
555 * Protection exceptions are suppressing, decrement psw address.
556 * The exception to this rule are aborted transactions, for these
557 * the PSW already points to the correct location.
558 */
559 if (!(regs->int_code & 0x200))
560 regs->psw.addr = __rewind_psw(regs->psw, regs->int_code >> 16);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200561 /*
562 * Check for low-address protection. This needs to be treated
563 * as a special case because the translation exception code
564 * field is not guaranteed to contain valid data in this case.
565 */
Martin Schwidefsky61365e12009-12-07 12:51:42 +0100566 if (unlikely(!(trans_exc_code & 4))) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100567 do_low_address(regs);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200568 return;
569 }
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100570 if (unlikely(MACHINE_HAS_NX && (trans_exc_code & 0x80))) {
571 regs->int_parm_long = (trans_exc_code & ~PAGE_MASK) |
572 (regs->psw.addr & PAGE_MASK);
573 access = VM_EXEC;
574 fault = VM_FAULT_BADACCESS;
575 } else {
576 access = VM_WRITE;
577 fault = do_exception(regs, access);
578 }
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100579 if (unlikely(fault))
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100580 do_fault_error(regs, access, fault);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
Heiko Carstens7a5388d2014-10-22 12:42:38 +0200582NOKPROBE_SYMBOL(do_protection_exception);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Heiko Carstens7a5388d2014-10-22 12:42:38 +0200584void do_dat_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Martin Schwidefsky1ab947d2009-12-07 12:51:46 +0100586 int access, fault;
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100587
Martin Schwidefsky1ab947d2009-12-07 12:51:46 +0100588 access = VM_READ | VM_EXEC | VM_WRITE;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100589 fault = do_exception(regs, access);
Martin Schwidefsky50d72802009-12-07 12:51:45 +0100590 if (unlikely(fault))
Martin Schwidefsky57d7f932016-03-22 10:54:24 +0100591 do_fault_error(regs, access, fault);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
Heiko Carstens7a5388d2014-10-22 12:42:38 +0200593NOKPROBE_SYMBOL(do_dat_exception);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#ifdef CONFIG_PFAULT
596/*
597 * 'pfault' pseudo page faults routines.
598 */
Heiko Carstensfb0a9d72011-01-05 12:47:39 +0100599static int pfault_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601static int __init nopfault(char *str)
602{
603 pfault_disable = 1;
604 return 1;
605}
606
607__setup("nopfault", nopfault);
608
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200609struct pfault_refbk {
610 u16 refdiagc;
611 u16 reffcode;
612 u16 refdwlen;
613 u16 refversn;
614 u64 refgaddr;
615 u64 refselmk;
616 u64 refcmpmk;
617 u64 reserved;
618} __attribute__ ((packed, aligned(8)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620int pfault_init(void)
621{
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200622 struct pfault_refbk refbk = {
623 .refdiagc = 0x258,
624 .reffcode = 0,
625 .refdwlen = 5,
626 .refversn = 2,
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200627 .refgaddr = __LC_LPP,
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200628 .refselmk = 1ULL << 48,
629 .refcmpmk = 1ULL << 48,
630 .reserved = __PF_RES_FIELD };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 int rc;
632
Carsten Ottef32269a2011-12-27 11:27:11 +0100633 if (pfault_disable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return -1;
Martin Schwidefsky1ec27722015-08-20 17:28:44 +0200635 diag_stat_inc(DIAG_STAT_X258);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200636 asm volatile(
637 " diag %1,%0,0x258\n"
638 "0: j 2f\n"
639 "1: la %0,8\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 "2:\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200641 EX_TABLE(0b,1b)
642 : "=d" (rc) : "a" (&refbk), "m" (refbk) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return rc;
644}
645
646void pfault_fini(void)
647{
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200648 struct pfault_refbk refbk = {
649 .refdiagc = 0x258,
650 .reffcode = 1,
651 .refdwlen = 5,
652 .refversn = 2,
653 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Carsten Ottef32269a2011-12-27 11:27:11 +0100655 if (pfault_disable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return;
Martin Schwidefsky1ec27722015-08-20 17:28:44 +0200657 diag_stat_inc(DIAG_STAT_X258);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200658 asm volatile(
659 " diag %0,0,0x258\n"
Heiko Carstens6c22c982016-06-10 09:57:05 +0200660 "0: nopr %%r7\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200661 EX_TABLE(0b,0b)
662 : : "a" (&refbk), "m" (refbk) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200665static DEFINE_SPINLOCK(pfault_lock);
666static LIST_HEAD(pfault_list);
667
Peter Zijlstra0227f7c2016-03-22 21:42:53 +0100668#define PF_COMPLETE 0x0080
669
670/*
671 * The mechanism of our pfault code: if Linux is running as guest, runs a user
672 * space process and the user space process accesses a page that the host has
673 * paged out we get a pfault interrupt.
674 *
675 * This allows us, within the guest, to schedule a different process. Without
676 * this mechanism the host would have to suspend the whole virtual cpu until
677 * the page has been paged in.
678 *
679 * So when we get such an interrupt then we set the state of the current task
680 * to uninterruptible and also set the need_resched flag. Both happens within
681 * interrupt context(!). If we later on want to return to user space we
682 * recognize the need_resched flag and then call schedule(). It's not very
683 * obvious how this works...
684 *
685 * Of course we have a lot of additional fun with the completion interrupt (->
686 * host signals that a page of a process has been paged in and the process can
687 * continue to run). This interrupt can arrive on any cpu and, since we have
688 * virtual cpus, actually appear before the interrupt that signals that a page
689 * is missing.
690 */
Heiko Carstensfde15c32012-03-11 11:59:31 -0400691static void pfault_interrupt(struct ext_code ext_code,
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200692 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 struct task_struct *tsk;
695 __u16 subcode;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200696 pid_t pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 /*
Peter Zijlstra0227f7c2016-03-22 21:42:53 +0100699 * Get the external interruption subcode & pfault initial/completion
700 * signal bit. VM stores this in the 'cpu address' field associated
701 * with the external interrupt.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 */
Heiko Carstensfde15c32012-03-11 11:59:31 -0400703 subcode = ext_code.subcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if ((subcode & 0xff00) != __SUBCODE_MASK)
705 return;
Heiko Carstens420f42e2013-01-02 15:18:18 +0100706 inc_irq_stat(IRQEXT_PFL);
Heiko Carstens54c27792012-05-10 09:44:35 +0200707 /* Get the token (= pid of the affected task). */
Christian Borntraegere22cf8c2015-10-06 18:06:15 +0200708 pid = param64 & LPP_PFAULT_PID_MASK;
Heiko Carstens54c27792012-05-10 09:44:35 +0200709 rcu_read_lock();
710 tsk = find_task_by_pid_ns(pid, &init_pid_ns);
711 if (tsk)
712 get_task_struct(tsk);
713 rcu_read_unlock();
714 if (!tsk)
715 return;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200716 spin_lock(&pfault_lock);
Peter Zijlstra0227f7c2016-03-22 21:42:53 +0100717 if (subcode & PF_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 /* signal bit is set -> a page has been swapped in by VM */
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200719 if (tsk->thread.pfault_wait == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 /* Initial interrupt was faster than the completion
721 * interrupt. pfault_wait is valid. Set pfault_wait
722 * back to zero and wake up the process. This can
723 * safely be done because the task is still sleeping
Martin Schwidefskyb6d09442005-09-03 15:58:02 -0700724 * and can't produce new pfaults. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 tsk->thread.pfault_wait = 0;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200726 list_del(&tsk->thread.list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 wake_up_process(tsk);
Heiko Carstensd5e50a52012-05-09 09:37:30 +0200728 put_task_struct(tsk);
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200729 } else {
730 /* Completion interrupt was faster than initial
731 * interrupt. Set pfault_wait to -1 so the initial
Heiko Carstensfa2fb2f2011-11-14 11:19:01 +0100732 * interrupt doesn't put the task to sleep.
733 * If the task is not running, ignore the completion
734 * interrupt since it must be a leftover of a PFAULT
735 * CANCEL operation which didn't remove all pending
736 * completion interrupts. */
737 if (tsk->state == TASK_RUNNING)
738 tsk->thread.pfault_wait = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740 } else {
741 /* signal bit not set -> a real page is missing. */
Heiko Carstensd49f47f2012-05-10 10:47:21 +0200742 if (WARN_ON_ONCE(tsk != current))
743 goto out;
Heiko Carstensd5e50a52012-05-09 09:37:30 +0200744 if (tsk->thread.pfault_wait == 1) {
745 /* Already on the list with a reference: put to sleep */
Peter Zijlstra0227f7c2016-03-22 21:42:53 +0100746 goto block;
Heiko Carstensd5e50a52012-05-09 09:37:30 +0200747 } else if (tsk->thread.pfault_wait == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /* Completion interrupt was faster than the initial
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200749 * interrupt (pfault_wait == -1). Set pfault_wait
750 * back to zero and exit. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 tsk->thread.pfault_wait = 0;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200752 } else {
753 /* Initial interrupt arrived before completion
Heiko Carstensd5e50a52012-05-09 09:37:30 +0200754 * interrupt. Let the task sleep.
755 * An extra task reference is needed since a different
756 * cpu may set the task state to TASK_RUNNING again
757 * before the scheduler is reached. */
758 get_task_struct(tsk);
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200759 tsk->thread.pfault_wait = 1;
760 list_add(&tsk->thread.list, &pfault_list);
Peter Zijlstra0227f7c2016-03-22 21:42:53 +0100761block:
762 /* Since this must be a userspace fault, there
763 * is no kernel task state to trample. Rely on the
764 * return to userspace schedule() to block. */
765 __set_current_state(TASK_UNINTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 set_tsk_need_resched(tsk);
Martin Schwidefskyc3601922016-10-25 12:21:44 +0200767 set_preempt_need_resched();
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 }
Heiko Carstensd49f47f2012-05-10 10:47:21 +0200770out:
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200771 spin_unlock(&pfault_lock);
Heiko Carstens54c27792012-05-10 09:44:35 +0200772 put_task_struct(tsk);
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200773}
774
Sebastian Andrzej Siewior84c9cee2016-09-06 19:04:53 +0200775static int pfault_cpu_dead(unsigned int cpu)
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200776{
777 struct thread_struct *thread, *next;
778 struct task_struct *tsk;
779
Sebastian Andrzej Siewior84c9cee2016-09-06 19:04:53 +0200780 spin_lock_irq(&pfault_lock);
781 list_for_each_entry_safe(thread, next, &pfault_list, list) {
782 thread->pfault_wait = 0;
783 list_del(&thread->list);
784 tsk = container_of(thread, struct task_struct, thread);
785 wake_up_process(tsk);
786 put_task_struct(tsk);
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200787 }
Sebastian Andrzej Siewior84c9cee2016-09-06 19:04:53 +0200788 spin_unlock_irq(&pfault_lock);
789 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Heiko Carstensfb0a9d72011-01-05 12:47:39 +0100792static int __init pfault_irq_init(void)
Heiko Carstens29b08d22006-12-04 15:40:40 +0100793{
Heiko Carstensfb0a9d72011-01-05 12:47:39 +0100794 int rc;
Heiko Carstens29b08d22006-12-04 15:40:40 +0100795
Thomas Huth1dad0932014-03-31 15:24:08 +0200796 rc = register_external_irq(EXT_IRQ_CP_SERVICE, pfault_interrupt);
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200797 if (rc)
798 goto out_extint;
799 rc = pfault_init() == 0 ? 0 : -EOPNOTSUPP;
800 if (rc)
801 goto out_pfault;
Heiko Carstens82003c32013-09-04 13:35:45 +0200802 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
Sebastian Andrzej Siewior84c9cee2016-09-06 19:04:53 +0200803 cpuhp_setup_state_nocalls(CPUHP_S390_PFAULT_DEAD, "s390/pfault:dead",
804 NULL, pfault_cpu_dead);
Heiko Carstensfb0a9d72011-01-05 12:47:39 +0100805 return 0;
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200806
807out_pfault:
Thomas Huth1dad0932014-03-31 15:24:08 +0200808 unregister_external_irq(EXT_IRQ_CP_SERVICE, pfault_interrupt);
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200809out_extint:
810 pfault_disable = 1;
811 return rc;
Heiko Carstens29b08d22006-12-04 15:40:40 +0100812}
Heiko Carstensfb0a9d72011-01-05 12:47:39 +0100813early_initcall(pfault_irq_init);
814
Heiko Carstens7dd8fe12011-05-23 10:24:35 +0200815#endif /* CONFIG_PFAULT */