unsigned long get_tm_stackpointer(struct pt_regs *regs) { /* When in an active transaction that takes a signal, we need to be * careful with the stack. It's possible that the stack has moved back * up after the tbegin. The obvious case here is when the tbegin is * called inside a function that returns before a tend. In this case, * the stack is part of the checkpointed transactional memory state. * If we write over this non transactionally or in suspend, we are in * trouble because if we get a tm abort, the program counter and stack * pointer will be back at the tbegin but our in memory stack won't be * valid anymore. * * To avoid this, when taking a signal in an active transaction, we * need to use the stack pointer from the checkpointed state, rather * than the speculated state. This ensures that the signal context * (written tm suspended) will be written below the stack required for * the rollback. The transaction is aborted becuase of the treclaim, * so any memory written between the tbegin and the signal will be * rolled back anyway. * * For signals taken in non-TM or suspended mode, we use the * normal/non-checkpointed stack pointer. */ #ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE(regs->msr)) { tm_reclaim_current(TM_CAUSE_SIGNAL); if (MSR_TM_TRANSACTIONAL(regs->msr)) return current->thread.ckpt_regs.gpr[1]; } #endif return regs->gpr[1]; }
int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6, unsigned long r7, unsigned long r8, struct pt_regs *regs) { struct ucontext __user *uc = (struct ucontext __user *)regs->gpr[1]; sigset_t set; #ifdef CONFIG_PPC_TRANSACTIONAL_MEM unsigned long msr; #endif BUG_ON(current->thread.regs != regs); /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; if (!access_ok(VERIFY_READ, uc, sizeof(*uc))) goto badframe; if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) goto badframe; set_current_blocked(&set); #ifdef CONFIG_PPC_TRANSACTIONAL_MEM /* * If there is a transactional state then throw it away. * The purpose of a sigreturn is to destroy all traces of the * signal frame, this includes any transactional state created * within in. We only check for suspended as we can never be * active in the kernel, we are active, there is nothing better to * do than go ahead and Bad Thing later. * The cause is not important as there will never be a * recheckpoint so it's not user visible. */ if (MSR_TM_SUSPENDED(mfmsr())) tm_reclaim_current(0); if (__get_user(msr, &uc->uc_mcontext.gp_regs[PT_MSR])) goto badframe; if (MSR_TM_ACTIVE(msr)) { /* We recheckpoint on return. */ struct ucontext __user *uc_transact; if (__get_user(uc_transact, &uc->uc_link)) goto badframe; if (restore_tm_sigcontexts(current, &uc->uc_mcontext, &uc_transact->uc_mcontext)) goto badframe; } else /* Fall through, for non-TM restore */ #endif if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext)) goto badframe; if (restore_altstack(&uc->uc_stack)) goto badframe; set_thread_flag(TIF_RESTOREALL); return 0; badframe: if (show_unhandled_signals) printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, current->comm, current->pid, "rt_sigreturn", (long)uc, regs->nip, regs->link); force_sig(SIGSEGV, current); return 0; }