aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/process_64.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/process_64.c')
-rw-r--r--arch/x86/kernel/process_64.c197
1 files changed, 104 insertions, 93 deletions
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 71553b664e2a..cd8c0ed02b7e 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -37,11 +37,11 @@
37#include <linux/kdebug.h> 37#include <linux/kdebug.h>
38#include <linux/tick.h> 38#include <linux/tick.h>
39#include <linux/prctl.h> 39#include <linux/prctl.h>
40#include <linux/uaccess.h>
41#include <linux/io.h>
40 42
41#include <asm/uaccess.h>
42#include <asm/pgtable.h> 43#include <asm/pgtable.h>
43#include <asm/system.h> 44#include <asm/system.h>
44#include <asm/io.h>
45#include <asm/processor.h> 45#include <asm/processor.h>
46#include <asm/i387.h> 46#include <asm/i387.h>
47#include <asm/mmu_context.h> 47#include <asm/mmu_context.h>
@@ -51,6 +51,7 @@
51#include <asm/proto.h> 51#include <asm/proto.h>
52#include <asm/ia32.h> 52#include <asm/ia32.h>
53#include <asm/idle.h> 53#include <asm/idle.h>
54#include <asm/syscalls.h>
54 55
55asmlinkage extern void ret_from_fork(void); 56asmlinkage extern void ret_from_fork(void);
56 57
@@ -85,28 +86,12 @@ void exit_idle(void)
85 __exit_idle(); 86 __exit_idle();
86} 87}
87 88
88#ifdef CONFIG_HOTPLUG_CPU 89#ifndef CONFIG_SMP
89DECLARE_PER_CPU(int, cpu_state);
90
91#include <asm/nmi.h>
92/* We halt the CPU with physical CPU hotplug */
93static inline void play_dead(void)
94{
95 idle_task_exit();
96 mb();
97 /* Ack it */
98 __get_cpu_var(cpu_state) = CPU_DEAD;
99
100 local_irq_disable();
101 /* mask all interrupts, flush any and all caches, and halt */
102 wbinvd_halt();
103}
104#else
105static inline void play_dead(void) 90static inline void play_dead(void)
106{ 91{
107 BUG(); 92 BUG();
108} 93}
109#endif /* CONFIG_HOTPLUG_CPU */ 94#endif
110 95
111/* 96/*
112 * The idle thread. There's no useful work to be 97 * The idle thread. There's no useful work to be
@@ -151,7 +136,7 @@ void cpu_idle(void)
151} 136}
152 137
153/* Prints also some state that isn't saved in the pt_regs */ 138/* Prints also some state that isn't saved in the pt_regs */
154void __show_regs(struct pt_regs * regs) 139void __show_regs(struct pt_regs *regs, int all)
155{ 140{
156 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs; 141 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
157 unsigned long d0, d1, d2, d3, d6, d7; 142 unsigned long d0, d1, d2, d3, d6, d7;
@@ -160,60 +145,65 @@ void __show_regs(struct pt_regs * regs)
160 145
161 printk("\n"); 146 printk("\n");
162 print_modules(); 147 print_modules();
163 printk("Pid: %d, comm: %.20s %s %s %.*s\n", 148 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s\n",
164 current->pid, current->comm, print_tainted(), 149 current->pid, current->comm, print_tainted(),
165 init_utsname()->release, 150 init_utsname()->release,
166 (int)strcspn(init_utsname()->version, " "), 151 (int)strcspn(init_utsname()->version, " "),
167 init_utsname()->version); 152 init_utsname()->version);
168 printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip); 153 printk(KERN_INFO "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
169 printk_address(regs->ip, 1); 154 printk_address(regs->ip, 1);
170 printk("RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->sp, 155 printk(KERN_INFO "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss,
171 regs->flags); 156 regs->sp, regs->flags);
172 printk("RAX: %016lx RBX: %016lx RCX: %016lx\n", 157 printk(KERN_INFO "RAX: %016lx RBX: %016lx RCX: %016lx\n",
173 regs->ax, regs->bx, regs->cx); 158 regs->ax, regs->bx, regs->cx);
174 printk("RDX: %016lx RSI: %016lx RDI: %016lx\n", 159 printk(KERN_INFO "RDX: %016lx RSI: %016lx RDI: %016lx\n",
175 regs->dx, regs->si, regs->di); 160 regs->dx, regs->si, regs->di);
176 printk("RBP: %016lx R08: %016lx R09: %016lx\n", 161 printk(KERN_INFO "RBP: %016lx R08: %016lx R09: %016lx\n",
177 regs->bp, regs->r8, regs->r9); 162 regs->bp, regs->r8, regs->r9);
178 printk("R10: %016lx R11: %016lx R12: %016lx\n", 163 printk(KERN_INFO "R10: %016lx R11: %016lx R12: %016lx\n",
179 regs->r10, regs->r11, regs->r12); 164 regs->r10, regs->r11, regs->r12);
180 printk("R13: %016lx R14: %016lx R15: %016lx\n", 165 printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n",
181 regs->r13, regs->r14, regs->r15); 166 regs->r13, regs->r14, regs->r15);
182 167
183 asm("movl %%ds,%0" : "=r" (ds)); 168 asm("movl %%ds,%0" : "=r" (ds));
184 asm("movl %%cs,%0" : "=r" (cs)); 169 asm("movl %%cs,%0" : "=r" (cs));
185 asm("movl %%es,%0" : "=r" (es)); 170 asm("movl %%es,%0" : "=r" (es));
186 asm("movl %%fs,%0" : "=r" (fsindex)); 171 asm("movl %%fs,%0" : "=r" (fsindex));
187 asm("movl %%gs,%0" : "=r" (gsindex)); 172 asm("movl %%gs,%0" : "=r" (gsindex));
188 173
189 rdmsrl(MSR_FS_BASE, fs); 174 rdmsrl(MSR_FS_BASE, fs);
190 rdmsrl(MSR_GS_BASE, gs); 175 rdmsrl(MSR_GS_BASE, gs);
191 rdmsrl(MSR_KERNEL_GS_BASE, shadowgs); 176 rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
177
178 if (!all)
179 return;
192 180
193 cr0 = read_cr0(); 181 cr0 = read_cr0();
194 cr2 = read_cr2(); 182 cr2 = read_cr2();
195 cr3 = read_cr3(); 183 cr3 = read_cr3();
196 cr4 = read_cr4(); 184 cr4 = read_cr4();
197 185
198 printk("FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n", 186 printk(KERN_INFO "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
199 fs,fsindex,gs,gsindex,shadowgs); 187 fs, fsindex, gs, gsindex, shadowgs);
200 printk("CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0); 188 printk(KERN_INFO "CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
201 printk("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4); 189 es, cr0);
190 printk(KERN_INFO "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
191 cr4);
202 192
203 get_debugreg(d0, 0); 193 get_debugreg(d0, 0);
204 get_debugreg(d1, 1); 194 get_debugreg(d1, 1);
205 get_debugreg(d2, 2); 195 get_debugreg(d2, 2);
206 printk("DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2); 196 printk(KERN_INFO "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
207 get_debugreg(d3, 3); 197 get_debugreg(d3, 3);
208 get_debugreg(d6, 6); 198 get_debugreg(d6, 6);
209 get_debugreg(d7, 7); 199 get_debugreg(d7, 7);
210 printk("DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7); 200 printk(KERN_INFO "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
211} 201}
212 202
213void show_regs(struct pt_regs *regs) 203void show_regs(struct pt_regs *regs)
214{ 204{
215 printk("CPU %d:", smp_processor_id()); 205 printk(KERN_INFO "CPU %d:", smp_processor_id());
216 __show_regs(regs); 206 __show_regs(regs, 1);
217 show_trace(NULL, regs, (void *)(regs + 1), regs->bp); 207 show_trace(NULL, regs, (void *)(regs + 1), regs->bp);
218} 208}
219 209
@@ -238,6 +228,14 @@ void exit_thread(void)
238 t->io_bitmap_max = 0; 228 t->io_bitmap_max = 0;
239 put_cpu(); 229 put_cpu();
240 } 230 }
231#ifdef CONFIG_X86_DS
232 /* Free any DS contexts that have not been properly released. */
233 if (unlikely(t->ds_ctx)) {
234 /* we clear debugctl to make sure DS is not used. */
235 update_debugctlmsr(0);
236 ds_free(t->ds_ctx);
237 }
238#endif /* CONFIG_X86_DS */
241} 239}
242 240
243void flush_thread(void) 241void flush_thread(void)
@@ -313,10 +311,10 @@ void prepare_to_copy(struct task_struct *tsk)
313 311
314int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, 312int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
315 unsigned long unused, 313 unsigned long unused,
316 struct task_struct * p, struct pt_regs * regs) 314 struct task_struct *p, struct pt_regs *regs)
317{ 315{
318 int err; 316 int err;
319 struct pt_regs * childregs; 317 struct pt_regs *childregs;
320 struct task_struct *me = current; 318 struct task_struct *me = current;
321 319
322 childregs = ((struct pt_regs *) 320 childregs = ((struct pt_regs *)
@@ -361,10 +359,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
361 if (test_thread_flag(TIF_IA32)) 359 if (test_thread_flag(TIF_IA32))
362 err = do_set_thread_area(p, -1, 360 err = do_set_thread_area(p, -1,
363 (struct user_desc __user *)childregs->si, 0); 361 (struct user_desc __user *)childregs->si, 0);
364 else 362 else
365#endif 363#endif
366 err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8); 364 err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8);
367 if (err) 365 if (err)
368 goto out; 366 goto out;
369 } 367 }
370 err = 0; 368 err = 0;
@@ -471,13 +469,27 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
471 next = &next_p->thread; 469 next = &next_p->thread;
472 470
473 debugctl = prev->debugctlmsr; 471 debugctl = prev->debugctlmsr;
474 if (next->ds_area_msr != prev->ds_area_msr) { 472
475 /* we clear debugctl to make sure DS 473#ifdef CONFIG_X86_DS
476 * is not in use when we change it */ 474 {
477 debugctl = 0; 475 unsigned long ds_prev = 0, ds_next = 0;
478 update_debugctlmsr(0); 476
479 wrmsrl(MSR_IA32_DS_AREA, next->ds_area_msr); 477 if (prev->ds_ctx)
478 ds_prev = (unsigned long)prev->ds_ctx->ds;
479 if (next->ds_ctx)
480 ds_next = (unsigned long)next->ds_ctx->ds;
481
482 if (ds_next != ds_prev) {
483 /*
484 * We clear debugctl to make sure DS
485 * is not in use when we change it:
486 */
487 debugctl = 0;
488 update_debugctlmsr(0);
489 wrmsrl(MSR_IA32_DS_AREA, ds_next);
490 }
480 } 491 }
492#endif /* CONFIG_X86_DS */
481 493
482 if (next->debugctlmsr != debugctl) 494 if (next->debugctlmsr != debugctl)
483 update_debugctlmsr(next->debugctlmsr); 495 update_debugctlmsr(next->debugctlmsr);
@@ -515,13 +527,13 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
515 memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); 527 memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
516 } 528 }
517 529
518#ifdef X86_BTS 530#ifdef CONFIG_X86_PTRACE_BTS
519 if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS)) 531 if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS))
520 ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS); 532 ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS);
521 533
522 if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS)) 534 if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS))
523 ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES); 535 ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES);
524#endif 536#endif /* CONFIG_X86_PTRACE_BTS */
525} 537}
526 538
527/* 539/*
@@ -543,7 +555,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
543 unsigned fsindex, gsindex; 555 unsigned fsindex, gsindex;
544 556
545 /* we're going to use this soon, after a few expensive things */ 557 /* we're going to use this soon, after a few expensive things */
546 if (next_p->fpu_counter>5) 558 if (next_p->fpu_counter > 5)
547 prefetch(next->xstate); 559 prefetch(next->xstate);
548 560
549 /* 561 /*
@@ -551,13 +563,13 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
551 */ 563 */
552 load_sp0(tss, next); 564 load_sp0(tss, next);
553 565
554 /* 566 /*
555 * Switch DS and ES. 567 * Switch DS and ES.
556 * This won't pick up thread selector changes, but I guess that is ok. 568 * This won't pick up thread selector changes, but I guess that is ok.
557 */ 569 */
558 savesegment(es, prev->es); 570 savesegment(es, prev->es);
559 if (unlikely(next->es | prev->es)) 571 if (unlikely(next->es | prev->es))
560 loadsegment(es, next->es); 572 loadsegment(es, next->es);
561 573
562 savesegment(ds, prev->ds); 574 savesegment(ds, prev->ds);
563 if (unlikely(next->ds | prev->ds)) 575 if (unlikely(next->ds | prev->ds))
@@ -583,7 +595,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
583 */ 595 */
584 arch_leave_lazy_cpu_mode(); 596 arch_leave_lazy_cpu_mode();
585 597
586 /* 598 /*
587 * Switch FS and GS. 599 * Switch FS and GS.
588 * 600 *
589 * Segment register != 0 always requires a reload. Also 601 * Segment register != 0 always requires a reload. Also
@@ -592,13 +604,13 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
592 */ 604 */
593 if (unlikely(fsindex | next->fsindex | prev->fs)) { 605 if (unlikely(fsindex | next->fsindex | prev->fs)) {
594 loadsegment(fs, next->fsindex); 606 loadsegment(fs, next->fsindex);
595 /* 607 /*
596 * Check if the user used a selector != 0; if yes 608 * Check if the user used a selector != 0; if yes
597 * clear 64bit base, since overloaded base is always 609 * clear 64bit base, since overloaded base is always
598 * mapped to the Null selector 610 * mapped to the Null selector
599 */ 611 */
600 if (fsindex) 612 if (fsindex)
601 prev->fs = 0; 613 prev->fs = 0;
602 } 614 }
603 /* when next process has a 64bit base use it */ 615 /* when next process has a 64bit base use it */
604 if (next->fs) 616 if (next->fs)
@@ -608,7 +620,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
608 if (unlikely(gsindex | next->gsindex | prev->gs)) { 620 if (unlikely(gsindex | next->gsindex | prev->gs)) {
609 load_gs_index(next->gsindex); 621 load_gs_index(next->gsindex);
610 if (gsindex) 622 if (gsindex)
611 prev->gs = 0; 623 prev->gs = 0;
612 } 624 }
613 if (next->gs) 625 if (next->gs)
614 wrmsrl(MSR_KERNEL_GS_BASE, next->gs); 626 wrmsrl(MSR_KERNEL_GS_BASE, next->gs);
@@ -617,12 +629,12 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
617 /* Must be after DS reload */ 629 /* Must be after DS reload */
618 unlazy_fpu(prev_p); 630 unlazy_fpu(prev_p);
619 631
620 /* 632 /*
621 * Switch the PDA and FPU contexts. 633 * Switch the PDA and FPU contexts.
622 */ 634 */
623 prev->usersp = read_pda(oldrsp); 635 prev->usersp = read_pda(oldrsp);
624 write_pda(oldrsp, next->usersp); 636 write_pda(oldrsp, next->usersp);
625 write_pda(pcurrent, next_p); 637 write_pda(pcurrent, next_p);
626 638
627 write_pda(kernelstack, 639 write_pda(kernelstack,
628 (unsigned long)task_stack_page(next_p) + 640 (unsigned long)task_stack_page(next_p) +
@@ -663,7 +675,7 @@ long sys_execve(char __user *name, char __user * __user *argv,
663 char __user * __user *envp, struct pt_regs *regs) 675 char __user * __user *envp, struct pt_regs *regs)
664{ 676{
665 long error; 677 long error;
666 char * filename; 678 char *filename;
667 679
668 filename = getname(name); 680 filename = getname(name);
669 error = PTR_ERR(filename); 681 error = PTR_ERR(filename);
@@ -721,55 +733,55 @@ asmlinkage long sys_vfork(struct pt_regs *regs)
721unsigned long get_wchan(struct task_struct *p) 733unsigned long get_wchan(struct task_struct *p)
722{ 734{
723 unsigned long stack; 735 unsigned long stack;
724 u64 fp,ip; 736 u64 fp, ip;
725 int count = 0; 737 int count = 0;
726 738
727 if (!p || p == current || p->state==TASK_RUNNING) 739 if (!p || p == current || p->state == TASK_RUNNING)
728 return 0; 740 return 0;
729 stack = (unsigned long)task_stack_page(p); 741 stack = (unsigned long)task_stack_page(p);
730 if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE) 742 if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
731 return 0; 743 return 0;
732 fp = *(u64 *)(p->thread.sp); 744 fp = *(u64 *)(p->thread.sp);
733 do { 745 do {
734 if (fp < (unsigned long)stack || 746 if (fp < (unsigned long)stack ||
735 fp > (unsigned long)stack+THREAD_SIZE) 747 fp >= (unsigned long)stack+THREAD_SIZE)
736 return 0; 748 return 0;
737 ip = *(u64 *)(fp+8); 749 ip = *(u64 *)(fp+8);
738 if (!in_sched_functions(ip)) 750 if (!in_sched_functions(ip))
739 return ip; 751 return ip;
740 fp = *(u64 *)fp; 752 fp = *(u64 *)fp;
741 } while (count++ < 16); 753 } while (count++ < 16);
742 return 0; 754 return 0;
743} 755}
744 756
745long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) 757long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
746{ 758{
747 int ret = 0; 759 int ret = 0;
748 int doit = task == current; 760 int doit = task == current;
749 int cpu; 761 int cpu;
750 762
751 switch (code) { 763 switch (code) {
752 case ARCH_SET_GS: 764 case ARCH_SET_GS:
753 if (addr >= TASK_SIZE_OF(task)) 765 if (addr >= TASK_SIZE_OF(task))
754 return -EPERM; 766 return -EPERM;
755 cpu = get_cpu(); 767 cpu = get_cpu();
756 /* handle small bases via the GDT because that's faster to 768 /* handle small bases via the GDT because that's faster to
757 switch. */ 769 switch. */
758 if (addr <= 0xffffffff) { 770 if (addr <= 0xffffffff) {
759 set_32bit_tls(task, GS_TLS, addr); 771 set_32bit_tls(task, GS_TLS, addr);
760 if (doit) { 772 if (doit) {
761 load_TLS(&task->thread, cpu); 773 load_TLS(&task->thread, cpu);
762 load_gs_index(GS_TLS_SEL); 774 load_gs_index(GS_TLS_SEL);
763 } 775 }
764 task->thread.gsindex = GS_TLS_SEL; 776 task->thread.gsindex = GS_TLS_SEL;
765 task->thread.gs = 0; 777 task->thread.gs = 0;
766 } else { 778 } else {
767 task->thread.gsindex = 0; 779 task->thread.gsindex = 0;
768 task->thread.gs = addr; 780 task->thread.gs = addr;
769 if (doit) { 781 if (doit) {
770 load_gs_index(0); 782 load_gs_index(0);
771 ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr); 783 ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr);
772 } 784 }
773 } 785 }
774 put_cpu(); 786 put_cpu();
775 break; 787 break;
@@ -823,8 +835,7 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
823 rdmsrl(MSR_KERNEL_GS_BASE, base); 835 rdmsrl(MSR_KERNEL_GS_BASE, base);
824 else 836 else
825 base = task->thread.gs; 837 base = task->thread.gs;
826 } 838 } else
827 else
828 base = task->thread.gs; 839 base = task->thread.gs;
829 ret = put_user(base, (unsigned long __user *)addr); 840 ret = put_user(base, (unsigned long __user *)addr);
830 break; 841 break;