X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=arch%2Fppc64%2Fkernel%2Fprocess.c;h=d1c152db959b9f2a232d2661eb8e37a401fa607f;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=be153b95917451743bbef0dca4efe698fb9974d3;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/arch/ppc64/kernel/process.c b/arch/ppc64/kernel/process.c index be153b959..d1c152db9 100644 --- a/arch/ppc64/kernel/process.c +++ b/arch/ppc64/kernel/process.c @@ -34,7 +34,8 @@ #include #include #include -#include +#include +#include #include #include @@ -47,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -65,8 +65,43 @@ struct mm_struct ioremap_mm = { .page_table_lock = SPIN_LOCK_UNLOCKED, }; +/* + * Make sure the floating-point register state in the + * the thread_struct is up to date for task tsk. + */ +void flush_fp_to_thread(struct task_struct *tsk) +{ + if (tsk->thread.regs) { + /* + * We need to disable preemption here because if we didn't, + * another process could get scheduled after the regs->msr + * test but before we have finished saving the FP registers + * to the thread_struct. That process could take over the + * FPU, and then when we get scheduled again we would store + * bogus values for the remaining FP registers. + */ + preempt_disable(); + if (tsk->thread.regs->msr & MSR_FP) { +#ifdef CONFIG_SMP + /* + * This should only ever be called for current or + * for a stopped child process. Since we save away + * the FP register state on context switch on SMP, + * there is something wrong if a stopped child appears + * to still have its FP state in the CPU registers. + */ + BUG_ON(tsk != current); +#endif + giveup_fpu(current); + } + preempt_enable(); + } +} + void enable_kernel_fp(void) { + WARN_ON(preemptible()); + #ifdef CONFIG_SMP if (current->thread.regs && (current->thread.regs->msr & MSR_FP)) giveup_fpu(current); @@ -80,12 +115,9 @@ EXPORT_SYMBOL(enable_kernel_fp); int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs) { - struct pt_regs *regs = tsk->thread.regs; - - if (!regs) + if (!tsk->thread.regs) return 0; - if (tsk == current && (regs->msr & MSR_FP)) - giveup_fpu(current); + flush_fp_to_thread(current); memcpy(fpregs, &tsk->thread.fpr[0], sizeof(*fpregs)); @@ -96,6 +128,8 @@ int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs) void enable_kernel_altivec(void) { + WARN_ON(preemptible()); + #ifdef CONFIG_SMP if (current->thread.regs && (current->thread.regs->msr & MSR_VEC)) giveup_altivec(current); @@ -107,10 +141,27 @@ void enable_kernel_altivec(void) } EXPORT_SYMBOL(enable_kernel_altivec); +/* + * Make sure the VMX/Altivec register state in the + * the thread_struct is up to date for task tsk. + */ +void flush_altivec_to_thread(struct task_struct *tsk) +{ + if (tsk->thread.regs) { + preempt_disable(); + if (tsk->thread.regs->msr & MSR_VEC) { +#ifdef CONFIG_SMP + BUG_ON(tsk != current); +#endif + giveup_altivec(current); + } + preempt_enable(); + } +} + int dump_task_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs) { - if (regs->msr & MSR_VEC) - giveup_altivec(current); + flush_altivec_to_thread(current); memcpy(vrregs, ¤t->thread.vr[0], sizeof(*vrregs)); return 1; } @@ -163,21 +214,57 @@ struct task_struct *__switch_to(struct task_struct *prev, return last; } +static int instructions_to_print = 16; + +static void show_instructions(struct pt_regs *regs) +{ + int i; + unsigned long pc = regs->nip - (instructions_to_print * 3 / 4 * + sizeof(int)); + + printk("Instruction dump:"); + + for (i = 0; i < instructions_to_print; i++) { + int instr; + + if (!(i % 8)) + printk("\n"); + + if (((REGION_ID(pc) != KERNEL_REGION_ID) && + (REGION_ID(pc) != VMALLOC_REGION_ID)) || + __get_user(instr, (unsigned int *)pc)) { + printk("XXXXXXXX "); + } else { + if (regs->nip == pc) + printk("<%08x> ", instr); + else + printk("%08x ", instr); + } + + pc += sizeof(int); + } + + printk("\n"); +} + void show_regs(struct pt_regs * regs) { int i; + unsigned long trap; - printk("NIP: %016lX XER: %016lX LR: %016lX\n", - regs->nip, regs->xer, regs->link); + printk("NIP: %016lX XER: %08X LR: %016lX CTR: %016lX\n", + regs->nip, (unsigned int)regs->xer, regs->link, regs->ctr); printk("REGS: %p TRAP: %04lx %s (%s)\n", - regs, regs->trap, print_tainted(), UTS_RELEASE); - printk("MSR: %016lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n", + regs, regs->trap, print_tainted(), system_utsname.release); + printk("MSR: %016lx EE: %01x PR: %01x FP: %01x ME: %01x " + "IR/DR: %01x%01x CR: %08X\n", regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0, regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0, regs->msr&MSR_IR ? 1 : 0, - regs->msr&MSR_DR ? 1 : 0); - if (regs->trap == 0x300 || regs->trap == 0x380 || regs->trap == 0x600) - printk("DAR: %016lx, DSISR: %016lx\n", regs->dar, regs->dsisr); + regs->msr&MSR_DR ? 1 : 0, + (unsigned int)regs->ccr); + trap = TRAP(regs); + printk("DAR: %016lx DSISR: %016lx\n", regs->dar, regs->dsisr); printk("TASK: %p[%d] '%s' THREAD: %p", current, current->pid, current->comm, current->thread_info); @@ -191,6 +278,8 @@ void show_regs(struct pt_regs * regs) } printk("%016lX ", regs->gpr[i]); + if (i == 13 && !FULL_REGS(regs)) + break; } printk("\n"); /* @@ -202,6 +291,8 @@ void show_regs(struct pt_regs * regs) printk("LR [%016lx] ", regs->link); print_symbol("%s\n", regs->link); show_stack(current, (unsigned long *)regs->gpr[1]); + if (!user_mode(regs)) + show_instructions(regs); } void exit_thread(void) @@ -245,16 +336,8 @@ release_thread(struct task_struct *t) */ void prepare_to_copy(struct task_struct *tsk) { - struct pt_regs *regs = tsk->thread.regs; - - if (regs == NULL) - return; - if (regs->msr & MSR_FP) - giveup_fpu(current); -#ifdef CONFIG_ALTIVEC - if (regs->msr & MSR_VEC) - giveup_altivec(current); -#endif /* CONFIG_ALTIVEC */ + flush_fp_to_thread(current); + flush_altivec_to_thread(current); } /* @@ -268,8 +351,6 @@ copy_thread(int nr, unsigned long clone_flags, unsigned long usp, extern void ret_from_fork(void); unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE; - p->set_child_tid = p->clear_child_tid = NULL; - /* Copy registers */ sp -= sizeof(struct pt_regs); childregs = (struct pt_regs *) sp; @@ -307,6 +388,16 @@ copy_thread(int nr, unsigned long clone_flags, unsigned long usp, kregs = (struct pt_regs *) sp; sp -= STACK_FRAME_OVERHEAD; p->thread.ksp = sp; + if (cur_cpu_spec->cpu_features & CPU_FTR_SLB) { + unsigned long sp_vsid = get_kernel_vsid(sp); + + sp_vsid <<= SLB_VSID_SHIFT; + sp_vsid |= SLB_VSID_KERNEL; + if (cur_cpu_spec->cpu_features & CPU_FTR_16M_PAGE) + sp_vsid |= SLB_VSID_L; + + p->thread.ksp_vsid = sp_vsid; + } /* * The PPC64 ABI makes use of a TOC to contain function @@ -338,11 +429,22 @@ void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp) /* Check whether the e_entry function descriptor entries * need to be relocated before we can use them. */ - if ( load_addr != 0 ) { + if (load_addr != 0) { entry += load_addr; toc += load_addr; } + /* + * If we exec out of a kernel thread then thread.regs will not be + * set. Do it now. + */ + if (!current->thread.regs) { + unsigned long childregs = (unsigned long)current->thread_info + + THREAD_SIZE; + childregs -= sizeof(struct pt_regs); + current->thread.regs = (struct pt_regs *)childregs; + } + regs->nip = entry; regs->gpr[1] = sp; regs->gpr[2] = toc; @@ -409,7 +511,7 @@ int sys_clone(unsigned long clone_flags, unsigned long p2, unsigned long p3, } } - return do_fork(clone_flags & ~CLONE_IDLETASK, p2, regs, 0, + return do_fork(clone_flags, p2, regs, 0, (int __user *)parent_tidptr, (int __user *)child_tidptr); } @@ -439,17 +541,16 @@ int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2, error = PTR_ERR(filename); if (IS_ERR(filename)) goto out; - if (regs->msr & MSR_FP) - giveup_fpu(current); -#ifdef CONFIG_ALTIVEC - if (regs->msr & MSR_VEC) - giveup_altivec(current); -#endif /* CONFIG_ALTIVEC */ + flush_fp_to_thread(current); + flush_altivec_to_thread(current); error = do_execve(filename, (char __user * __user *) a1, (char __user * __user *) a2, regs); - if (error == 0) + if (error == 0) { + task_lock(current); current->ptrace &= ~PT_DTRACE; + task_unlock(current); + } putname(filename); out: