^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1994 - 2000 Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2014, Imagination Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/irqflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/uprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/abi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/fpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <asm/sim.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <asm/ucontext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <asm/cpu-features.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/war.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/dsp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/inst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/msa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "signal-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int (*save_fp_context)(void __user *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int (*restore_fp_context)(void __user *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct sigframe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 sf_ass[4]; /* argument save space for o32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 sf_pad[2]; /* Was: signal trampoline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Matches struct ucontext from its uc_mcontext field onwards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct sigcontext sf_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) sigset_t sf_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned long long sf_extcontext[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct rt_sigframe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u32 rs_ass[4]; /* argument save space for o32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u32 rs_pad[2]; /* Was: signal trampoline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct siginfo rs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct ucontext rs_uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #ifdef CONFIG_MIPS_FP_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Thread saved context copy to/from a signal context presumed to be on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * user stack, and therefore accessed with appropriate macros from uaccess.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int copy_fp_to_sigcontext(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) for (i = 0; i < NUM_FPU_REGS; i += inc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) err |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __put_user(get_fpr64(¤t->thread.fpu.fpr[i], 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) &fpregs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) err |= __put_user(current->thread.fpu.fcr31, csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int copy_fp_from_sigcontext(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u64 fpr_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) for (i = 0; i < NUM_FPU_REGS; i += inc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) err |= __get_user(fpr_val, &fpregs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) set_fpr64(¤t->thread.fpu.fpr[i], 0, fpr_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) err |= __get_user(current->thread.fpu.fcr31, csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #else /* !CONFIG_MIPS_FP_SUPPORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int copy_fp_to_sigcontext(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int copy_fp_from_sigcontext(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif /* !CONFIG_MIPS_FP_SUPPORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Wrappers for the assembly _{save,restore}_fp_context functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int save_hw_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return _save_fp_context(fpregs, csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int restore_hw_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return _restore_fp_context(fpregs, csr);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Extended context handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline void __user *sc_to_extcontext(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct ucontext __user *uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * We can just pretend the sigcontext is always embedded in a struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * ucontext here, because the offset from sigcontext to extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * context is the same in the struct sigframe case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) uc = container_of(sc, struct ucontext, uc_mcontext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return &uc->uc_extcontext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #ifdef CONFIG_CPU_HAS_MSA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int save_msa_extcontext(void __user *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct msa_extcontext __user *msa = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) uint64_t val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!thread_msa_context_live())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Ensure that we can't lose the live MSA context between checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * for it & writing it to memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (is_msa_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * There are no EVA versions of the vector register load/store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * instructions, so MSA context has to be saved to kernel memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * and then copied to user memory. The save to kernel memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * should already have been done when handling scalar FP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) BUG_ON(IS_ENABLED(CONFIG_EVA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) err = __put_user(read_msa_csr(), &msa->csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) err |= _save_msa_all_upper(&msa->wr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) err = __put_user(current->thread.fpu.msacsr, &msa->csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) for (i = 0; i < NUM_FPU_REGS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) val = get_fpr64(¤t->thread.fpu.fpr[i], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err |= __put_user(val, &msa->wr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) err |= __put_user(MSA_EXTCONTEXT_MAGIC, &msa->ext.magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) err |= __put_user(sizeof(*msa), &msa->ext.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return err ? -EFAULT : sizeof(*msa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int restore_msa_extcontext(void __user *buf, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct msa_extcontext __user *msa = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) unsigned long long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) unsigned int csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (size != sizeof(*msa))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) err = get_user(csr, &msa->csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (is_msa_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * There are no EVA versions of the vector register load/store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * instructions, so MSA context has to be copied to kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * memory and later loaded to registers. The same is true of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * scalar FP context, so FPU & MSA should have already been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * disabled whilst handling scalar FP context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) BUG_ON(IS_ENABLED(CONFIG_EVA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) write_msa_csr(csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) err |= _restore_msa_all_upper(&msa->wr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) current->thread.fpu.msacsr = csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) for (i = 0; i < NUM_FPU_REGS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) err |= __get_user(val, &msa->wr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) set_fpr64(¤t->thread.fpu.fpr[i], 1, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #else /* !CONFIG_CPU_HAS_MSA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int save_msa_extcontext(void __user *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return 0;
^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 int restore_msa_extcontext(void __user *buf, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return SIGSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #endif /* !CONFIG_CPU_HAS_MSA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int save_extcontext(void __user *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) sz = save_msa_extcontext(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (sz < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) buf += sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* If no context was saved then trivially return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Write the end marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (__put_user(END_EXTCONTEXT_MAGIC, (u32 *)buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sz += sizeof(((struct extcontext *)NULL)->magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int restore_extcontext(void __user *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct extcontext ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) err = __get_user(ext.magic, (unsigned int *)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (ext.magic == END_EXTCONTEXT_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) err = __get_user(ext.size, (unsigned int *)(buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) + offsetof(struct extcontext, size)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) switch (ext.magic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) case MSA_EXTCONTEXT_MAGIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err = restore_msa_extcontext(buf, ext.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) buf += ext.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * Helper routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int protected_save_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) uint32_t __user *used_math = sc + abi->off_sc_used_math;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) unsigned int used, ext_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) used = used_math() ? USED_FP : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (!used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) goto fp_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!test_thread_flag(TIF_32BIT_FPREGS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) used |= USED_FR1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (test_thread_flag(TIF_HYBRID_FPREGS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) used |= USED_HYBRID_FPRS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * EVA does not have userland equivalents of ldc1 or sdc1, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * save to the kernel FP context & copy that to userland below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (IS_ENABLED(CONFIG_EVA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) lose_fpu(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) lock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (is_fpu_owner()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) err = save_fp_context(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) unlock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) unlock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) err = copy_fp_to_sigcontext(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (likely(!err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* touch the sigcontext and try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) err = __put_user(0, &fpregs[0]) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) __put_user(0, &fpregs[31]) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) __put_user(0, csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return err; /* really bad sigcontext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) fp_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ext_sz = err = save_extcontext(sc_to_extcontext(sc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) used |= ext_sz ? USED_EXTCONTEXT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return __put_user(used, used_math);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) int protected_restore_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) uint32_t __user *used_math = sc + abi->off_sc_used_math;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) unsigned int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int err, sig = 0, tmp __maybe_unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) err = __get_user(used, used_math);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) conditional_used_math(used & USED_FP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * The signal handler may have used FPU; give it up if the program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * doesn't want it following sigreturn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (err || !(used & USED_FP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) lose_fpu(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (!(used & USED_FP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto fp_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) err = sig = fpcsr_pending(csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * EVA does not have userland equivalents of ldc1 or sdc1, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * disable the FPU here such that the code below simply copies to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * the kernel FP context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (IS_ENABLED(CONFIG_EVA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) lose_fpu(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) lock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (is_fpu_owner()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) err = restore_fp_context(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) unlock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) unlock_fpu_owner();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) err = copy_fp_from_sigcontext(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (likely(!err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* touch the sigcontext and try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) err = __get_user(tmp, &fpregs[0]) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) __get_user(tmp, &fpregs[31]) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) __get_user(tmp, csr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) break; /* really bad sigcontext */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) fp_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!err && (used & USED_EXTCONTEXT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) err = restore_extcontext(sc_to_extcontext(sc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return err ?: sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) err |= __put_user(regs->cp0_epc, &sc->sc_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) err |= __put_user(0, &sc->sc_regs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) for (i = 1; i < 32; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) #ifdef CONFIG_CPU_HAS_SMARTMIPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) err |= __put_user(regs->acx, &sc->sc_acx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) err |= __put_user(regs->hi, &sc->sc_mdhi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) err |= __put_user(regs->lo, &sc->sc_mdlo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (cpu_has_dsp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) err |= __put_user(mfhi1(), &sc->sc_hi1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) err |= __put_user(mflo1(), &sc->sc_lo1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err |= __put_user(mfhi2(), &sc->sc_hi2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) err |= __put_user(mflo2(), &sc->sc_lo2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) err |= __put_user(mfhi3(), &sc->sc_hi3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) err |= __put_user(mflo3(), &sc->sc_lo3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * Save FPU state to signal context. Signal handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * will "inherit" current FPU state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) err |= protected_save_fp_context(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static size_t extcontext_max_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) size_t sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * The assumption here is that between this point & the point at which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * the extended context is saved the size of the context should only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * ever be able to shrink (if the task is preempted), but never grow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * That is, what this function returns is an upper bound on the size of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * the extended context for the current task at the current time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (thread_msa_context_live())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) sz += sizeof(struct msa_extcontext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* If any context is saved then we'll append the end marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) sz += sizeof(((struct extcontext *)NULL)->magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int fpcsr_pending(unsigned int __user *fpcsr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int err, sig = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) unsigned int csr, enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) err = __get_user(csr, fpcsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * If the signal handler set some FPU exceptions, clear it and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * send SIGFPE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (csr & enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) csr &= ~enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) err |= __put_user(csr, fpcsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) sig = SIGFPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return err ?: sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) unsigned long treg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Always make any pending restarted system calls return -EINTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) current->restart_block.fn = do_no_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) err |= __get_user(regs->cp0_epc, &sc->sc_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) #ifdef CONFIG_CPU_HAS_SMARTMIPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) err |= __get_user(regs->acx, &sc->sc_acx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) err |= __get_user(regs->hi, &sc->sc_mdhi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) err |= __get_user(regs->lo, &sc->sc_mdlo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (cpu_has_dsp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) for (i = 1; i < 32; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return err ?: protected_restore_fp_context(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #ifdef CONFIG_WAR_ICACHE_REFILLS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #define SIGMASK ~(cpu_icache_line_size()-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) #define SIGMASK ALMASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) size_t frame_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) unsigned long sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* Leave space for potential extended context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) frame_size += extcontext_max_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* Default to using normal stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) sp = regs->regs[29];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * FPU emulator may have it's own trampoline active just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * above the user stack, 16-bytes before the next lowest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * 16 byte boundary. Try to avoid trashing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) sp -= 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) sp = sigsp(sp, ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return (void __user *)((sp - frame_size) & SIGMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * Atomically swap in the new signal mask, and wait for a signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) #ifdef CONFIG_TRAD_SIGNALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) SYSCALL_DEFINE1(sigsuspend, sigset_t __user *, uset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return sys_rt_sigsuspend(uset, sizeof(sigset_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) #ifdef CONFIG_TRAD_SIGNALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) SYSCALL_DEFINE3(sigaction, int, sig, const struct sigaction __user *, act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct sigaction __user *, oact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct k_sigaction new_ka, old_ka;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) old_sigset_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!access_ok(act, sizeof(*act)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) err |= __get_user(mask, &act->sa_mask.sig[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) siginitset(&new_ka.sa.sa_mask, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!ret && oact) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (!access_ok(oact, sizeof(*oact)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) err |= __put_user(0, &oact->sa_mask.sig[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) err |= __put_user(0, &oact->sa_mask.sig[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) err |= __put_user(0, &oact->sa_mask.sig[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) #ifdef CONFIG_TRAD_SIGNALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) asmlinkage void sys_sigreturn(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct pt_regs *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) sigset_t blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) frame = (struct sigframe __user *)regs->regs[29];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) set_current_blocked(&blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) sig = restore_sigcontext(regs, &frame->sf_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (sig < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) else if (sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) force_sig(sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * Don't let your children do this ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) __asm__ __volatile__(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) "move\t$29, %0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) "j\tsyscall_exit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) : /* no outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) : "r" (regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /* Unreached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #endif /* CONFIG_TRAD_SIGNALS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) asmlinkage void sys_rt_sigreturn(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct pt_regs *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) int sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) frame = (struct rt_sigframe __user *)regs->regs[29];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (sig < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) else if (sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) force_sig(sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (restore_altstack(&frame->rs_uc.uc_stack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * Don't let your children do this ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) __asm__ __volatile__(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) "move\t$29, %0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) "j\tsyscall_exit"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) : /* no outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) : "r" (regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /* Unreached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) #ifdef CONFIG_TRAD_SIGNALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static int setup_frame(void *sig_return, struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) struct pt_regs *regs, sigset_t *set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) frame = get_sigframe(ksig, regs, sizeof(*frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!access_ok(frame, sizeof (*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) err |= setup_sigcontext(regs, &frame->sf_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * Arguments to signal handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * a0 = signal number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * a1 = 0 (should be cause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * a2 = pointer to struct sigcontext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * $25 and c0_epc point to the signal handler, $29 points to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * struct sigframe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) regs->regs[ 4] = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) regs->regs[ 5] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) regs->regs[ 6] = (unsigned long) &frame->sf_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) regs->regs[29] = (unsigned long) frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) regs->regs[31] = (unsigned long) sig_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) current->comm, current->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) frame, regs->cp0_epc, regs->regs[31]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct pt_regs *regs, sigset_t *set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) frame = get_sigframe(ksig, regs, sizeof(*frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (!access_ok(frame, sizeof (*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* Create siginfo. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) err |= copy_siginfo_to_user(&frame->rs_info, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /* Create the ucontext. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) err |= __put_user(0, &frame->rs_uc.uc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) err |= __put_user(NULL, &frame->rs_uc.uc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) err |= __save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * Arguments to signal handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) * a0 = signal number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * a1 = 0 (should be cause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * a2 = pointer to ucontext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * $25 and c0_epc point to the signal handler, $29 points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * the struct rt_sigframe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) regs->regs[ 4] = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) regs->regs[ 5] = (unsigned long) &frame->rs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) regs->regs[ 6] = (unsigned long) &frame->rs_uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) regs->regs[29] = (unsigned long) frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) regs->regs[31] = (unsigned long) sig_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) current->comm, current->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) frame, regs->cp0_epc, regs->regs[31]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct mips_abi mips_abi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) #ifdef CONFIG_TRAD_SIGNALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) .setup_frame = setup_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) .setup_rt_frame = setup_rt_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) .restart = __NR_restart_syscall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) .off_sc_fpregs = offsetof(struct sigcontext, sc_fpregs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) .off_sc_fpc_csr = offsetof(struct sigcontext, sc_fpc_csr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) .off_sc_used_math = offsetof(struct sigcontext, sc_used_math),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) .vdso = &vdso_image,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) sigset_t *oldset = sigmask_to_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct mips_abi *abi = current->thread.abi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) void *vdso = current->mm->context.vdso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * If we were emulating a delay slot instruction, exit that frame such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * that addresses in the sigframe are as expected for userland and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * don't have a problem if we reuse the thread's frame for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * instruction within the signal handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) dsemul_thread_rollback(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (regs->regs[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) switch(regs->regs[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) case ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) case ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) regs->regs[2] = EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) case ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) regs->regs[2] = EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) case ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) regs->regs[7] = regs->regs[26];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) regs->regs[2] = regs->regs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) regs->cp0_epc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) regs->regs[0] = 0; /* Don't deal with this again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) rseq_signal_deliver(ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (sig_uses_siginfo(&ksig->ka, abi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) ret = abi->setup_rt_frame(vdso + abi->vdso->off_rt_sigreturn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) ksig, regs, oldset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) ret = abi->setup_frame(vdso + abi->vdso->off_sigreturn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) ksig, regs, oldset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) signal_setup_done(ret, ksig, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) static void do_signal(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct ksignal ksig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (get_signal(&ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) /* Whee! Actually deliver the signal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) handle_signal(&ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (regs->regs[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) switch (regs->regs[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) case ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) case ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) case ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) regs->regs[2] = regs->regs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) regs->regs[7] = regs->regs[26];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) regs->cp0_epc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) case ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) regs->regs[2] = current->thread.abi->restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) regs->regs[7] = regs->regs[26];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) regs->cp0_epc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) regs->regs[0] = 0; /* Don't deal with this again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * If there's no signal to deliver, we just put the saved sigmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) * back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * notification of userspace execution resumption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) * - triggered by the TIF_WORK_MASK flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) __u32 thread_info_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) user_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (thread_info_flags & _TIF_UPROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) uprobe_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) /* deal with pending signal delivery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (thread_info_flags & _TIF_SIGPENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) do_signal(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (thread_info_flags & _TIF_NOTIFY_RESUME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) tracehook_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) rseq_handle_notify_resume(NULL, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) user_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) #if defined(CONFIG_SMP) && defined(CONFIG_MIPS_FP_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) static int smp_save_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return raw_cpu_has_fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) ? save_hw_fp_context(sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) : copy_fp_to_sigcontext(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static int smp_restore_fp_context(void __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return raw_cpu_has_fpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) ? restore_hw_fp_context(sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) : copy_fp_from_sigcontext(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static int signal_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * The offset from sigcontext to extended context should be the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * regardless of the type of signal, such that userland can always know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * where to look if it wishes to find the extended context structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) BUILD_BUG_ON((offsetof(struct sigframe, sf_extcontext) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) offsetof(struct sigframe, sf_sc)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) (offsetof(struct rt_sigframe, rs_uc.uc_extcontext) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) offsetof(struct rt_sigframe, rs_uc.uc_mcontext)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) #if defined(CONFIG_SMP) && defined(CONFIG_MIPS_FP_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) /* For now just do the cpu_has_fpu check when the functions are invoked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) save_fp_context = smp_save_fp_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) restore_fp_context = smp_restore_fp_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (cpu_has_fpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) save_fp_context = save_hw_fp_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) restore_fp_context = restore_hw_fp_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) save_fp_context = copy_fp_to_sigcontext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) restore_fp_context = copy_fp_from_sigcontext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) arch_initcall(signal_setup);