^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Common signal handling code for both 32 and 64 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Extracted from signal_32.c and signal_64.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Public License. See the file README.legal in the main directory of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * this archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/uprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/livepatch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/hw_breakpoint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/tm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "signal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #ifdef CONFIG_VSX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned long copy_fpr_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u64 buf[ELF_NFPREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* save FPR copy to local buffer then write to the thread_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) for (i = 0; i < (ELF_NFPREG - 1) ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) buf[i] = task->thread.TS_FPR(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) buf[i] = task->thread.fp_state.fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return __copy_to_user(to, buf, ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned long copy_fpr_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u64 buf[ELF_NFPREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (__copy_from_user(buf, from, ELF_NFPREG * sizeof(double)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) for (i = 0; i < (ELF_NFPREG - 1) ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) task->thread.TS_FPR(i) = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) task->thread.fp_state.fpscr = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long copy_vsx_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u64 buf[ELF_NVSRHALFREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* save FPR copy to local buffer then write to the thread_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (i = 0; i < ELF_NVSRHALFREG; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) buf[i] = task->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return __copy_to_user(to, buf, ELF_NVSRHALFREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned long copy_vsx_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u64 buf[ELF_NVSRHALFREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (__copy_from_user(buf, from, ELF_NVSRHALFREG * sizeof(double)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) for (i = 0; i < ELF_NVSRHALFREG ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) task->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned long copy_ckfpr_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u64 buf[ELF_NFPREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* save FPR copy to local buffer then write to the thread_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) for (i = 0; i < (ELF_NFPREG - 1) ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) buf[i] = task->thread.TS_CKFPR(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) buf[i] = task->thread.ckfp_state.fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return __copy_to_user(to, buf, ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long copy_ckfpr_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u64 buf[ELF_NFPREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (__copy_from_user(buf, from, ELF_NFPREG * sizeof(double)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) for (i = 0; i < (ELF_NFPREG - 1) ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) task->thread.TS_CKFPR(i) = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) task->thread.ckfp_state.fpscr = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned long copy_ckvsx_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u64 buf[ELF_NVSRHALFREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* save FPR copy to local buffer then write to the thread_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) for (i = 0; i < ELF_NVSRHALFREG; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) buf[i] = task->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return __copy_to_user(to, buf, ELF_NVSRHALFREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned long copy_ckvsx_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u64 buf[ELF_NVSRHALFREG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (__copy_from_user(buf, from, ELF_NVSRHALFREG * sizeof(double)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) for (i = 0; i < ELF_NVSRHALFREG ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) task->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) inline unsigned long copy_fpr_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return __copy_to_user(to, task->thread.fp_state.fpr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) inline unsigned long copy_fpr_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return __copy_from_user(task->thread.fp_state.fpr, from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) inline unsigned long copy_ckfpr_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return __copy_to_user(to, task->thread.ckfp_state.fpr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) inline unsigned long copy_ckfpr_from_user(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void __user *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return __copy_from_user(task->thread.ckfp_state.fpr, from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ELF_NFPREG * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Log an error when sending an unhandled signal to a process. Controlled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * through debug.exception-trace sysctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int show_unhandled_signals = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * Allocate space for the signal frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) void __user *get_sigframe(struct ksignal *ksig, unsigned long sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) size_t frame_size, int is_32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) unsigned long oldsp, newsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Default to using normal stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) oldsp = get_clean_sp(sp, is_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) oldsp = sigsp(oldsp, ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) newsp = (oldsp - frame_size) & ~0xFUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Check access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (!access_ok((void __user *)newsp, oldsp - newsp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return (void __user *)newsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int has_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned long ret = regs->gpr[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int restart = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* syscall ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!trap_is_syscall(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (trap_norestart(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* error signalled ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (trap_is_scv(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* 32-bit compat mode sign extend? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (!IS_ERR_VALUE(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ret = -ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) } else if (!(regs->ccr & 0x10000000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) case ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* ERESTARTNOHAND means that the syscall should only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * restarted if there was no handler for the signal, and since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * we only get here if there is a handler, we dont restart.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) restart = !has_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) case ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* ERESTARTSYS means to restart the syscall if there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * handler or the handler was registered with SA_RESTART
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) case ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* ERESTARTNOINTR means that the syscall should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * called again after the signal handler returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (restart) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (ret == ERESTART_RESTARTBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) regs->gpr[0] = __NR_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) regs->gpr[3] = regs->orig_gpr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) regs->nip -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) regs->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (trap_is_scv(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) regs->result = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) regs->gpr[3] = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) regs->result = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) regs->gpr[3] = EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) regs->ccr |= 0x10000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static void do_signal(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) sigset_t *oldset = sigmask_to_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct ksignal ksig = { .sig = 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) BUG_ON(tsk != current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) get_signal(&ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* Is there any syscall restart business here ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) check_syscall_restart(tsk->thread.regs, &ksig.ka, ksig.sig > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ksig.sig <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* No signal to deliver -- put the saved sigmask back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) set_trap_norestart(tsk->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return; /* no signals delivered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Reenable the DABR before delivering the signal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * user space. The DABR will have been cleared if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * triggered inside the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!IS_ENABLED(CONFIG_PPC_ADV_DEBUG_REGS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) for (i = 0; i < nr_wp_slots(); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (tsk->thread.hw_brk[i].address && tsk->thread.hw_brk[i].type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) __set_breakpoint(i, &tsk->thread.hw_brk[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* Re-enable the breakpoints for the signal stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) thread_change_pc(tsk, tsk->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) rseq_signal_deliver(&ksig, tsk->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (is_32bit_task()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (ksig.ka.sa.sa_flags & SA_SIGINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = handle_rt_signal32(&ksig, oldset, tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ret = handle_signal32(&ksig, oldset, tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ret = handle_rt_signal64(&ksig, oldset, tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) set_trap_norestart(tsk->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) signal_setup_done(ret, &ksig, test_thread_flag(TIF_SINGLESTEP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) user_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (thread_info_flags & _TIF_UPROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) uprobe_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (thread_info_flags & _TIF_PATCH_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) klp_update_patch_state(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (thread_info_flags & _TIF_SIGPENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) BUG_ON(regs != current->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) do_signal(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (thread_info_flags & _TIF_NOTIFY_RESUME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) tracehook_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) rseq_handle_notify_resume(NULL, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) user_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) unsigned long get_tm_stackpointer(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* When in an active transaction that takes a signal, we need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * careful with the stack. It's possible that the stack has moved back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * up after the tbegin. The obvious case here is when the tbegin is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * called inside a function that returns before a tend. In this case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * the stack is part of the checkpointed transactional memory state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * If we write over this non transactionally or in suspend, we are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * trouble because if we get a tm abort, the program counter and stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * pointer will be back at the tbegin but our in memory stack won't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * valid anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * To avoid this, when taking a signal in an active transaction, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * need to use the stack pointer from the checkpointed state, rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * than the speculated state. This ensures that the signal context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * (written tm suspended) will be written below the stack required for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * the rollback. The transaction is aborted because of the treclaim,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * so any memory written between the tbegin and the signal will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * rolled back anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * For signals taken in non-TM or suspended mode, we use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * normal/non-checkpointed stack pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) unsigned long ret = tsk->thread.regs->gpr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) BUG_ON(tsk != current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) tm_reclaim_current(TM_CAUSE_SIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (MSR_TM_TRANSACTIONAL(tsk->thread.regs->msr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ret = tsk->thread.ckpt_regs.gpr[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * If we treclaim, we must clear the current thread's TM bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * before re-enabling preemption. Otherwise we might be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * preempted and have the live MSR[TS] changed behind our back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * (tm_recheckpoint_new_task() would recheckpoint). Besides, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * enter the signal handler in non-transactional state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) tsk->thread.regs->msr &= ~MSR_TS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }