xref: /openbmc/linux/arch/arm64/kernel/signal.c (revision 727dede0)
1 /*
2  * Based on arch/arm/kernel/signal.c
3  *
4  * Copyright (C) 1995-2009 Russell King
5  * Copyright (C) 2012 ARM Ltd.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <linux/compat.h>
21 #include <linux/errno.h>
22 #include <linux/kernel.h>
23 #include <linux/signal.h>
24 #include <linux/personality.h>
25 #include <linux/freezer.h>
26 #include <linux/stddef.h>
27 #include <linux/uaccess.h>
28 #include <linux/sizes.h>
29 #include <linux/string.h>
30 #include <linux/tracehook.h>
31 #include <linux/ratelimit.h>
32 #include <linux/syscalls.h>
33 
34 #include <asm/debug-monitors.h>
35 #include <asm/elf.h>
36 #include <asm/cacheflush.h>
37 #include <asm/ucontext.h>
38 #include <asm/unistd.h>
39 #include <asm/fpsimd.h>
40 #include <asm/ptrace.h>
41 #include <asm/signal32.h>
42 #include <asm/vdso.h>
43 
44 /*
45  * Do a signal return; undo the signal stack. These are aligned to 128-bit.
46  */
47 struct rt_sigframe {
48 	struct siginfo info;
49 	struct ucontext uc;
50 };
51 
52 struct frame_record {
53 	u64 fp;
54 	u64 lr;
55 };
56 
57 struct rt_sigframe_user_layout {
58 	struct rt_sigframe __user *sigframe;
59 	struct frame_record __user *next_frame;
60 
61 	unsigned long size;	/* size of allocated sigframe data */
62 	unsigned long limit;	/* largest allowed size */
63 
64 	unsigned long fpsimd_offset;
65 	unsigned long esr_offset;
66 	unsigned long extra_offset;
67 	unsigned long end_offset;
68 };
69 
70 #define BASE_SIGFRAME_SIZE round_up(sizeof(struct rt_sigframe), 16)
71 #define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
72 #define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
73 
74 static void init_user_layout(struct rt_sigframe_user_layout *user)
75 {
76 	const size_t reserved_size =
77 		sizeof(user->sigframe->uc.uc_mcontext.__reserved);
78 
79 	memset(user, 0, sizeof(*user));
80 	user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved);
81 
82 	user->limit = user->size + reserved_size;
83 
84 	user->limit -= TERMINATOR_SIZE;
85 	user->limit -= EXTRA_CONTEXT_SIZE;
86 	/* Reserve space for extension and terminator ^ */
87 }
88 
89 static size_t sigframe_size(struct rt_sigframe_user_layout const *user)
90 {
91 	return round_up(max(user->size, sizeof(struct rt_sigframe)), 16);
92 }
93 
94 /*
95  * Sanity limit on the approximate maximum size of signal frame we'll
96  * try to generate.  Stack alignment padding and the frame record are
97  * not taken into account.  This limit is not a guarantee and is
98  * NOT ABI.
99  */
100 #define SIGFRAME_MAXSZ SZ_64K
101 
102 static int __sigframe_alloc(struct rt_sigframe_user_layout *user,
103 			    unsigned long *offset, size_t size, bool extend)
104 {
105 	size_t padded_size = round_up(size, 16);
106 
107 	if (padded_size > user->limit - user->size &&
108 	    !user->extra_offset &&
109 	    extend) {
110 		int ret;
111 
112 		user->limit += EXTRA_CONTEXT_SIZE;
113 		ret = __sigframe_alloc(user, &user->extra_offset,
114 				       sizeof(struct extra_context), false);
115 		if (ret) {
116 			user->limit -= EXTRA_CONTEXT_SIZE;
117 			return ret;
118 		}
119 
120 		/* Reserve space for the __reserved[] terminator */
121 		user->size += TERMINATOR_SIZE;
122 
123 		/*
124 		 * Allow expansion up to SIGFRAME_MAXSZ, ensuring space for
125 		 * the terminator:
126 		 */
127 		user->limit = SIGFRAME_MAXSZ - TERMINATOR_SIZE;
128 	}
129 
130 	/* Still not enough space?  Bad luck! */
131 	if (padded_size > user->limit - user->size)
132 		return -ENOMEM;
133 
134 	*offset = user->size;
135 	user->size += padded_size;
136 
137 	return 0;
138 }
139 
140 /*
141  * Allocate space for an optional record of <size> bytes in the user
142  * signal frame.  The offset from the signal frame base address to the
143  * allocated block is assigned to *offset.
144  */
145 static int sigframe_alloc(struct rt_sigframe_user_layout *user,
146 			  unsigned long *offset, size_t size)
147 {
148 	return __sigframe_alloc(user, offset, size, true);
149 }
150 
151 /* Allocate the null terminator record and prevent further allocations */
152 static int sigframe_alloc_end(struct rt_sigframe_user_layout *user)
153 {
154 	int ret;
155 
156 	/* Un-reserve the space reserved for the terminator: */
157 	user->limit += TERMINATOR_SIZE;
158 
159 	ret = sigframe_alloc(user, &user->end_offset,
160 			     sizeof(struct _aarch64_ctx));
161 	if (ret)
162 		return ret;
163 
164 	/* Prevent further allocation: */
165 	user->limit = user->size;
166 	return 0;
167 }
168 
169 static void __user *apply_user_offset(
170 	struct rt_sigframe_user_layout const *user, unsigned long offset)
171 {
172 	char __user *base = (char __user *)user->sigframe;
173 
174 	return base + offset;
175 }
176 
177 static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
178 {
179 	struct fpsimd_state *fpsimd = &current->thread.fpsimd_state;
180 	int err;
181 
182 	/* dump the hardware registers to the fpsimd_state structure */
183 	fpsimd_preserve_current_state();
184 
185 	/* copy the FP and status/control registers */
186 	err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs));
187 	__put_user_error(fpsimd->fpsr, &ctx->fpsr, err);
188 	__put_user_error(fpsimd->fpcr, &ctx->fpcr, err);
189 
190 	/* copy the magic/size information */
191 	__put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err);
192 	__put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err);
193 
194 	return err ? -EFAULT : 0;
195 }
196 
197 static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
198 {
199 	struct fpsimd_state fpsimd;
200 	__u32 magic, size;
201 	int err = 0;
202 
203 	/* check the magic/size information */
204 	__get_user_error(magic, &ctx->head.magic, err);
205 	__get_user_error(size, &ctx->head.size, err);
206 	if (err)
207 		return -EFAULT;
208 	if (magic != FPSIMD_MAGIC || size != sizeof(struct fpsimd_context))
209 		return -EINVAL;
210 
211 	/* copy the FP and status/control registers */
212 	err = __copy_from_user(fpsimd.vregs, ctx->vregs,
213 			       sizeof(fpsimd.vregs));
214 	__get_user_error(fpsimd.fpsr, &ctx->fpsr, err);
215 	__get_user_error(fpsimd.fpcr, &ctx->fpcr, err);
216 
217 	/* load the hardware registers from the fpsimd_state structure */
218 	if (!err)
219 		fpsimd_update_current_state(&fpsimd);
220 
221 	return err ? -EFAULT : 0;
222 }
223 
224 struct user_ctxs {
225 	struct fpsimd_context __user *fpsimd;
226 };
227 
228 static int parse_user_sigframe(struct user_ctxs *user,
229 			       struct rt_sigframe __user *sf)
230 {
231 	struct sigcontext __user *const sc = &sf->uc.uc_mcontext;
232 	struct _aarch64_ctx __user *head;
233 	char __user *base = (char __user *)&sc->__reserved;
234 	size_t offset = 0;
235 	size_t limit = sizeof(sc->__reserved);
236 	bool have_extra_context = false;
237 	char const __user *const sfp = (char const __user *)sf;
238 
239 	user->fpsimd = NULL;
240 
241 	if (!IS_ALIGNED((unsigned long)base, 16))
242 		goto invalid;
243 
244 	while (1) {
245 		int err = 0;
246 		u32 magic, size;
247 		char const __user *userp;
248 		struct extra_context const __user *extra;
249 		u64 extra_datap;
250 		u32 extra_size;
251 		struct _aarch64_ctx const __user *end;
252 		u32 end_magic, end_size;
253 
254 		if (limit - offset < sizeof(*head))
255 			goto invalid;
256 
257 		if (!IS_ALIGNED(offset, 16))
258 			goto invalid;
259 
260 		head = (struct _aarch64_ctx __user *)(base + offset);
261 		__get_user_error(magic, &head->magic, err);
262 		__get_user_error(size, &head->size, err);
263 		if (err)
264 			return err;
265 
266 		if (limit - offset < size)
267 			goto invalid;
268 
269 		switch (magic) {
270 		case 0:
271 			if (size)
272 				goto invalid;
273 
274 			goto done;
275 
276 		case FPSIMD_MAGIC:
277 			if (user->fpsimd)
278 				goto invalid;
279 
280 			if (size < sizeof(*user->fpsimd))
281 				goto invalid;
282 
283 			user->fpsimd = (struct fpsimd_context __user *)head;
284 			break;
285 
286 		case ESR_MAGIC:
287 			/* ignore */
288 			break;
289 
290 		case EXTRA_MAGIC:
291 			if (have_extra_context)
292 				goto invalid;
293 
294 			if (size < sizeof(*extra))
295 				goto invalid;
296 
297 			userp = (char const __user *)head;
298 
299 			extra = (struct extra_context const __user *)userp;
300 			userp += size;
301 
302 			__get_user_error(extra_datap, &extra->datap, err);
303 			__get_user_error(extra_size, &extra->size, err);
304 			if (err)
305 				return err;
306 
307 			/* Check for the dummy terminator in __reserved[]: */
308 
309 			if (limit - offset - size < TERMINATOR_SIZE)
310 				goto invalid;
311 
312 			end = (struct _aarch64_ctx const __user *)userp;
313 			userp += TERMINATOR_SIZE;
314 
315 			__get_user_error(end_magic, &end->magic, err);
316 			__get_user_error(end_size, &end->size, err);
317 			if (err)
318 				return err;
319 
320 			if (end_magic || end_size)
321 				goto invalid;
322 
323 			/* Prevent looping/repeated parsing of extra_context */
324 			have_extra_context = true;
325 
326 			base = (__force void __user *)extra_datap;
327 			if (!IS_ALIGNED((unsigned long)base, 16))
328 				goto invalid;
329 
330 			if (!IS_ALIGNED(extra_size, 16))
331 				goto invalid;
332 
333 			if (base != userp)
334 				goto invalid;
335 
336 			/* Reject "unreasonably large" frames: */
337 			if (extra_size > sfp + SIGFRAME_MAXSZ - userp)
338 				goto invalid;
339 
340 			/*
341 			 * Ignore trailing terminator in __reserved[]
342 			 * and start parsing extra data:
343 			 */
344 			offset = 0;
345 			limit = extra_size;
346 			continue;
347 
348 		default:
349 			goto invalid;
350 		}
351 
352 		if (size < sizeof(*head))
353 			goto invalid;
354 
355 		if (limit - offset < size)
356 			goto invalid;
357 
358 		offset += size;
359 	}
360 
361 done:
362 	if (!user->fpsimd)
363 		goto invalid;
364 
365 	return 0;
366 
367 invalid:
368 	return -EINVAL;
369 }
370 
371 static int restore_sigframe(struct pt_regs *regs,
372 			    struct rt_sigframe __user *sf)
373 {
374 	sigset_t set;
375 	int i, err;
376 	struct user_ctxs user;
377 
378 	err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
379 	if (err == 0)
380 		set_current_blocked(&set);
381 
382 	for (i = 0; i < 31; i++)
383 		__get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
384 				 err);
385 	__get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
386 	__get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
387 	__get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
388 
389 	/*
390 	 * Avoid sys_rt_sigreturn() restarting.
391 	 */
392 	forget_syscall(regs);
393 
394 	err |= !valid_user_regs(&regs->user_regs, current);
395 	if (err == 0)
396 		err = parse_user_sigframe(&user, sf);
397 
398 	if (err == 0)
399 		err = restore_fpsimd_context(user.fpsimd);
400 
401 	return err;
402 }
403 
404 asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
405 {
406 	struct rt_sigframe __user *frame;
407 
408 	/* Always make any pending restarted system calls return -EINTR */
409 	current->restart_block.fn = do_no_restart_syscall;
410 
411 	/*
412 	 * Since we stacked the signal on a 128-bit boundary, then 'sp' should
413 	 * be word aligned here.
414 	 */
415 	if (regs->sp & 15)
416 		goto badframe;
417 
418 	frame = (struct rt_sigframe __user *)regs->sp;
419 
420 	if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
421 		goto badframe;
422 
423 	if (restore_sigframe(regs, frame))
424 		goto badframe;
425 
426 	if (restore_altstack(&frame->uc.uc_stack))
427 		goto badframe;
428 
429 	return regs->regs[0];
430 
431 badframe:
432 	if (show_unhandled_signals)
433 		pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n",
434 				    current->comm, task_pid_nr(current), __func__,
435 				    regs->pc, regs->sp);
436 	force_sig(SIGSEGV, current);
437 	return 0;
438 }
439 
440 /* Determine the layout of optional records in the signal frame */
441 static int setup_sigframe_layout(struct rt_sigframe_user_layout *user)
442 {
443 	int err;
444 
445 	err = sigframe_alloc(user, &user->fpsimd_offset,
446 			     sizeof(struct fpsimd_context));
447 	if (err)
448 		return err;
449 
450 	/* fault information, if valid */
451 	if (current->thread.fault_code) {
452 		err = sigframe_alloc(user, &user->esr_offset,
453 				     sizeof(struct esr_context));
454 		if (err)
455 			return err;
456 	}
457 
458 	return sigframe_alloc_end(user);
459 }
460 
461 
462 static int setup_sigframe(struct rt_sigframe_user_layout *user,
463 			  struct pt_regs *regs, sigset_t *set)
464 {
465 	int i, err = 0;
466 	struct rt_sigframe __user *sf = user->sigframe;
467 
468 	/* set up the stack frame for unwinding */
469 	__put_user_error(regs->regs[29], &user->next_frame->fp, err);
470 	__put_user_error(regs->regs[30], &user->next_frame->lr, err);
471 
472 	for (i = 0; i < 31; i++)
473 		__put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
474 				 err);
475 	__put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
476 	__put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
477 	__put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
478 
479 	__put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err);
480 
481 	err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
482 
483 	if (err == 0) {
484 		struct fpsimd_context __user *fpsimd_ctx =
485 			apply_user_offset(user, user->fpsimd_offset);
486 		err |= preserve_fpsimd_context(fpsimd_ctx);
487 	}
488 
489 	/* fault information, if valid */
490 	if (err == 0 && user->esr_offset) {
491 		struct esr_context __user *esr_ctx =
492 			apply_user_offset(user, user->esr_offset);
493 
494 		__put_user_error(ESR_MAGIC, &esr_ctx->head.magic, err);
495 		__put_user_error(sizeof(*esr_ctx), &esr_ctx->head.size, err);
496 		__put_user_error(current->thread.fault_code, &esr_ctx->esr, err);
497 	}
498 
499 	if (err == 0 && user->extra_offset) {
500 		char __user *sfp = (char __user *)user->sigframe;
501 		char __user *userp =
502 			apply_user_offset(user, user->extra_offset);
503 
504 		struct extra_context __user *extra;
505 		struct _aarch64_ctx __user *end;
506 		u64 extra_datap;
507 		u32 extra_size;
508 
509 		extra = (struct extra_context __user *)userp;
510 		userp += EXTRA_CONTEXT_SIZE;
511 
512 		end = (struct _aarch64_ctx __user *)userp;
513 		userp += TERMINATOR_SIZE;
514 
515 		/*
516 		 * extra_datap is just written to the signal frame.
517 		 * The value gets cast back to a void __user *
518 		 * during sigreturn.
519 		 */
520 		extra_datap = (__force u64)userp;
521 		extra_size = sfp + round_up(user->size, 16) - userp;
522 
523 		__put_user_error(EXTRA_MAGIC, &extra->head.magic, err);
524 		__put_user_error(EXTRA_CONTEXT_SIZE, &extra->head.size, err);
525 		__put_user_error(extra_datap, &extra->datap, err);
526 		__put_user_error(extra_size, &extra->size, err);
527 
528 		/* Add the terminator */
529 		__put_user_error(0, &end->magic, err);
530 		__put_user_error(0, &end->size, err);
531 	}
532 
533 	/* set the "end" magic */
534 	if (err == 0) {
535 		struct _aarch64_ctx __user *end =
536 			apply_user_offset(user, user->end_offset);
537 
538 		__put_user_error(0, &end->magic, err);
539 		__put_user_error(0, &end->size, err);
540 	}
541 
542 	return err;
543 }
544 
545 static int get_sigframe(struct rt_sigframe_user_layout *user,
546 			 struct ksignal *ksig, struct pt_regs *regs)
547 {
548 	unsigned long sp, sp_top;
549 	int err;
550 
551 	init_user_layout(user);
552 	err = setup_sigframe_layout(user);
553 	if (err)
554 		return err;
555 
556 	sp = sp_top = sigsp(regs->sp, ksig);
557 
558 	sp = round_down(sp - sizeof(struct frame_record), 16);
559 	user->next_frame = (struct frame_record __user *)sp;
560 
561 	sp = round_down(sp, 16) - sigframe_size(user);
562 	user->sigframe = (struct rt_sigframe __user *)sp;
563 
564 	/*
565 	 * Check that we can actually write to the signal frame.
566 	 */
567 	if (!access_ok(VERIFY_WRITE, user->sigframe, sp_top - sp))
568 		return -EFAULT;
569 
570 	return 0;
571 }
572 
573 static void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
574 			 struct rt_sigframe_user_layout *user, int usig)
575 {
576 	__sigrestore_t sigtramp;
577 
578 	regs->regs[0] = usig;
579 	regs->sp = (unsigned long)user->sigframe;
580 	regs->regs[29] = (unsigned long)&user->next_frame->fp;
581 	regs->pc = (unsigned long)ka->sa.sa_handler;
582 
583 	if (ka->sa.sa_flags & SA_RESTORER)
584 		sigtramp = ka->sa.sa_restorer;
585 	else
586 		sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
587 
588 	regs->regs[30] = (unsigned long)sigtramp;
589 }
590 
591 static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
592 			  struct pt_regs *regs)
593 {
594 	struct rt_sigframe_user_layout user;
595 	struct rt_sigframe __user *frame;
596 	int err = 0;
597 
598 	if (get_sigframe(&user, ksig, regs))
599 		return 1;
600 
601 	frame = user.sigframe;
602 
603 	__put_user_error(0, &frame->uc.uc_flags, err);
604 	__put_user_error(NULL, &frame->uc.uc_link, err);
605 
606 	err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
607 	err |= setup_sigframe(&user, regs, set);
608 	if (err == 0) {
609 		setup_return(regs, &ksig->ka, &user, usig);
610 		if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
611 			err |= copy_siginfo_to_user(&frame->info, &ksig->info);
612 			regs->regs[1] = (unsigned long)&frame->info;
613 			regs->regs[2] = (unsigned long)&frame->uc;
614 		}
615 	}
616 
617 	return err;
618 }
619 
620 static void setup_restart_syscall(struct pt_regs *regs)
621 {
622 	if (is_compat_task())
623 		compat_setup_restart_syscall(regs);
624 	else
625 		regs->regs[8] = __NR_restart_syscall;
626 }
627 
628 /*
629  * OK, we're invoking a handler
630  */
631 static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
632 {
633 	struct task_struct *tsk = current;
634 	sigset_t *oldset = sigmask_to_save();
635 	int usig = ksig->sig;
636 	int ret;
637 
638 	/*
639 	 * Set up the stack frame
640 	 */
641 	if (is_compat_task()) {
642 		if (ksig->ka.sa.sa_flags & SA_SIGINFO)
643 			ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
644 		else
645 			ret = compat_setup_frame(usig, ksig, oldset, regs);
646 	} else {
647 		ret = setup_rt_frame(usig, ksig, oldset, regs);
648 	}
649 
650 	/*
651 	 * Check that the resulting registers are actually sane.
652 	 */
653 	ret |= !valid_user_regs(&regs->user_regs, current);
654 
655 	/*
656 	 * Fast forward the stepping logic so we step into the signal
657 	 * handler.
658 	 */
659 	if (!ret)
660 		user_fastforward_single_step(tsk);
661 
662 	signal_setup_done(ret, ksig, 0);
663 }
664 
665 /*
666  * Note that 'init' is a special process: it doesn't get signals it doesn't
667  * want to handle. Thus you cannot kill init even with a SIGKILL even by
668  * mistake.
669  *
670  * Note that we go through the signals twice: once to check the signals that
671  * the kernel can handle, and then we build all the user-level signal handling
672  * stack-frames in one go after that.
673  */
674 static void do_signal(struct pt_regs *regs)
675 {
676 	unsigned long continue_addr = 0, restart_addr = 0;
677 	int retval = 0;
678 	struct ksignal ksig;
679 
680 	/*
681 	 * If we were from a system call, check for system call restarting...
682 	 */
683 	if (in_syscall(regs)) {
684 		continue_addr = regs->pc;
685 		restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4);
686 		retval = regs->regs[0];
687 
688 		/*
689 		 * Avoid additional syscall restarting via ret_to_user.
690 		 */
691 		forget_syscall(regs);
692 
693 		/*
694 		 * Prepare for system call restart. We do this here so that a
695 		 * debugger will see the already changed PC.
696 		 */
697 		switch (retval) {
698 		case -ERESTARTNOHAND:
699 		case -ERESTARTSYS:
700 		case -ERESTARTNOINTR:
701 		case -ERESTART_RESTARTBLOCK:
702 			regs->regs[0] = regs->orig_x0;
703 			regs->pc = restart_addr;
704 			break;
705 		}
706 	}
707 
708 	/*
709 	 * Get the signal to deliver. When running under ptrace, at this point
710 	 * the debugger may change all of our registers.
711 	 */
712 	if (get_signal(&ksig)) {
713 		/*
714 		 * Depending on the signal settings, we may need to revert the
715 		 * decision to restart the system call, but skip this if a
716 		 * debugger has chosen to restart at a different PC.
717 		 */
718 		if (regs->pc == restart_addr &&
719 		    (retval == -ERESTARTNOHAND ||
720 		     retval == -ERESTART_RESTARTBLOCK ||
721 		     (retval == -ERESTARTSYS &&
722 		      !(ksig.ka.sa.sa_flags & SA_RESTART)))) {
723 			regs->regs[0] = -EINTR;
724 			regs->pc = continue_addr;
725 		}
726 
727 		handle_signal(&ksig, regs);
728 		return;
729 	}
730 
731 	/*
732 	 * Handle restarting a different system call. As above, if a debugger
733 	 * has chosen to restart at a different PC, ignore the restart.
734 	 */
735 	if (in_syscall(regs) && regs->pc == restart_addr) {
736 		if (retval == -ERESTART_RESTARTBLOCK)
737 			setup_restart_syscall(regs);
738 		user_rewind_single_step(current);
739 	}
740 
741 	restore_saved_sigmask();
742 }
743 
744 asmlinkage void do_notify_resume(struct pt_regs *regs,
745 				 unsigned int thread_flags)
746 {
747 	/*
748 	 * The assembly code enters us with IRQs off, but it hasn't
749 	 * informed the tracing code of that for efficiency reasons.
750 	 * Update the trace code with the current status.
751 	 */
752 	trace_hardirqs_off();
753 
754 	do {
755 		/* Check valid user FS if needed */
756 		addr_limit_user_check();
757 
758 		if (thread_flags & _TIF_NEED_RESCHED) {
759 			schedule();
760 		} else {
761 			local_irq_enable();
762 
763 			if (thread_flags & _TIF_UPROBE)
764 				uprobe_notify_resume(regs);
765 
766 			if (thread_flags & _TIF_SIGPENDING)
767 				do_signal(regs);
768 
769 			if (thread_flags & _TIF_NOTIFY_RESUME) {
770 				clear_thread_flag(TIF_NOTIFY_RESUME);
771 				tracehook_notify_resume(regs);
772 			}
773 
774 			if (thread_flags & _TIF_FOREIGN_FPSTATE)
775 				fpsimd_restore_current_state();
776 		}
777 
778 		local_irq_disable();
779 		thread_flags = READ_ONCE(current_thread_info()->flags);
780 	} while (thread_flags & _TIF_WORK_MASK);
781 }
782