ia64/linux-2.6.18-xen.hg

view arch/x86_64/kernel/process-xen.c @ 622:2b60a0b5432e

linux/x86-64: eliminate dead code

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jul 23 14:21:16 2008 +0100 (2008-07-23)
parents 2c80783731a2
children
line source
1 /*
2 * linux/arch/x86-64/kernel/process.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 *
6 * Pentium III FXSR, SSE support
7 * Gareth Hughes <gareth@valinux.com>, May 2000
8 *
9 * X86-64 port
10 * Andi Kleen.
11 *
12 * CPU hotplug support - ashok.raj@intel.com
13 *
14 * Jun Nakajima <jun.nakajima@intel.com>
15 * Modified for Xen
16 */
18 /*
19 * This file handles the architecture-dependent parts of process handling..
20 */
22 #include <stdarg.h>
24 #include <linux/cpu.h>
25 #include <linux/errno.h>
26 #include <linux/sched.h>
27 #include <linux/kernel.h>
28 #include <linux/mm.h>
29 #include <linux/elfcore.h>
30 #include <linux/smp.h>
31 #include <linux/slab.h>
32 #include <linux/user.h>
33 #include <linux/module.h>
34 #include <linux/a.out.h>
35 #include <linux/interrupt.h>
36 #include <linux/delay.h>
37 #include <linux/ptrace.h>
38 #include <linux/utsname.h>
39 #include <linux/random.h>
40 #include <linux/notifier.h>
41 #include <linux/kprobes.h>
43 #include <asm/uaccess.h>
44 #include <asm/pgtable.h>
45 #include <asm/system.h>
46 #include <asm/io.h>
47 #include <asm/processor.h>
48 #include <asm/i387.h>
49 #include <asm/mmu_context.h>
50 #include <asm/pda.h>
51 #include <asm/prctl.h>
52 #include <asm/kdebug.h>
53 #include <xen/interface/platform.h>
54 #include <xen/interface/physdev.h>
55 #include <xen/interface/vcpu.h>
56 #include <asm/desc.h>
57 #include <asm/proto.h>
58 #include <asm/hardirq.h>
59 #include <asm/ia32.h>
60 #include <asm/idle.h>
62 #include <xen/cpu_hotplug.h>
64 asmlinkage extern void ret_from_fork(void);
66 unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
68 unsigned long boot_option_idle_override = 0;
69 EXPORT_SYMBOL(boot_option_idle_override);
71 /*
72 * Powermanagement idle function, if any..
73 */
74 void (*pm_idle)(void);
75 EXPORT_SYMBOL(pm_idle);
76 static DEFINE_PER_CPU(unsigned int, cpu_idle_state);
78 static ATOMIC_NOTIFIER_HEAD(idle_notifier);
80 void idle_notifier_register(struct notifier_block *n)
81 {
82 atomic_notifier_chain_register(&idle_notifier, n);
83 }
84 EXPORT_SYMBOL_GPL(idle_notifier_register);
86 void idle_notifier_unregister(struct notifier_block *n)
87 {
88 atomic_notifier_chain_unregister(&idle_notifier, n);
89 }
90 EXPORT_SYMBOL(idle_notifier_unregister);
92 enum idle_state { CPU_IDLE, CPU_NOT_IDLE };
93 static DEFINE_PER_CPU(enum idle_state, idle_state) = CPU_NOT_IDLE;
95 void enter_idle(void)
96 {
97 __get_cpu_var(idle_state) = CPU_IDLE;
98 atomic_notifier_call_chain(&idle_notifier, IDLE_START, NULL);
99 }
101 static void __exit_idle(void)
102 {
103 __get_cpu_var(idle_state) = CPU_NOT_IDLE;
104 atomic_notifier_call_chain(&idle_notifier, IDLE_END, NULL);
105 }
107 /* Called from interrupts to signify idle end */
108 void exit_idle(void)
109 {
110 if (current->pid | read_pda(irqcount))
111 return;
112 __exit_idle();
113 }
115 /*
116 * On SMP it's slightly faster (but much more power-consuming!)
117 * to poll the ->need_resched flag instead of waiting for the
118 * cross-CPU IPI to arrive. Use this option with caution.
119 */
120 static void poll_idle (void)
121 {
122 local_irq_enable();
124 asm volatile(
125 "2:"
126 "testl %0,%1;"
127 "rep; nop;"
128 "je 2b;"
129 : :
130 "i" (_TIF_NEED_RESCHED),
131 "m" (current_thread_info()->flags));
132 }
134 static void xen_idle(void)
135 {
136 local_irq_disable();
138 if (need_resched())
139 local_irq_enable();
140 else {
141 current_thread_info()->status &= ~TS_POLLING;
142 smp_mb__after_clear_bit();
143 safe_halt();
144 current_thread_info()->status |= TS_POLLING;
145 }
146 }
148 #ifdef CONFIG_HOTPLUG_CPU
149 static inline void play_dead(void)
150 {
151 idle_task_exit();
152 local_irq_disable();
153 cpu_clear(smp_processor_id(), cpu_initialized);
154 preempt_enable_no_resched();
155 VOID(HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL));
156 cpu_bringup();
157 }
158 #else
159 static inline void play_dead(void)
160 {
161 BUG();
162 }
163 #endif /* CONFIG_HOTPLUG_CPU */
165 /*
166 * The idle thread. There's no useful work to be
167 * done, so just try to conserve power and have a
168 * low exit latency (ie sit in a loop waiting for
169 * somebody to say that they'd like to reschedule)
170 */
171 void cpu_idle (void)
172 {
173 current_thread_info()->status |= TS_POLLING;
174 /* endless idle loop with no priority at all */
175 while (1) {
176 while (!need_resched()) {
177 void (*idle)(void);
179 if (__get_cpu_var(cpu_idle_state))
180 __get_cpu_var(cpu_idle_state) = 0;
181 rmb();
182 idle = xen_idle; /* no alternatives */
183 if (cpu_is_offline(smp_processor_id()))
184 play_dead();
185 enter_idle();
186 idle();
187 __exit_idle();
188 }
190 preempt_enable_no_resched();
191 schedule();
192 preempt_disable();
193 }
194 }
196 void cpu_idle_wait(void)
197 {
198 unsigned int cpu, this_cpu = get_cpu();
199 cpumask_t map;
201 set_cpus_allowed(current, cpumask_of_cpu(this_cpu));
202 put_cpu();
204 cpus_clear(map);
205 for_each_online_cpu(cpu) {
206 per_cpu(cpu_idle_state, cpu) = 1;
207 cpu_set(cpu, map);
208 }
210 __get_cpu_var(cpu_idle_state) = 0;
212 wmb();
213 do {
214 ssleep(1);
215 for_each_online_cpu(cpu) {
216 if (cpu_isset(cpu, map) &&
217 !per_cpu(cpu_idle_state, cpu))
218 cpu_clear(cpu, map);
219 }
220 cpus_and(map, map, cpu_online_map);
221 } while (!cpus_empty(map));
222 }
223 EXPORT_SYMBOL_GPL(cpu_idle_wait);
225 void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
226 {
227 }
229 static int __init idle_setup (char *str)
230 {
231 if (!strncmp(str, "poll", 4)) {
232 printk("using polling idle threads.\n");
233 pm_idle = poll_idle;
234 }
236 boot_option_idle_override = 1;
237 return 1;
238 }
240 __setup("idle=", idle_setup);
242 /* Prints also some state that isn't saved in the pt_regs */
243 void __show_regs(struct pt_regs * regs)
244 {
245 unsigned long fs, gs, shadowgs;
246 unsigned int fsindex,gsindex;
247 unsigned int ds,cs,es;
249 printk("\n");
250 print_modules();
251 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
252 current->pid, current->comm, print_tainted(),
253 system_utsname.release,
254 (int)strcspn(system_utsname.version, " "),
255 system_utsname.version);
256 printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip);
257 printk_address(regs->rip);
258 printk("RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->rsp,
259 regs->eflags);
260 printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
261 regs->rax, regs->rbx, regs->rcx);
262 printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
263 regs->rdx, regs->rsi, regs->rdi);
264 printk("RBP: %016lx R08: %016lx R09: %016lx\n",
265 regs->rbp, regs->r8, regs->r9);
266 printk("R10: %016lx R11: %016lx R12: %016lx\n",
267 regs->r10, regs->r11, regs->r12);
268 printk("R13: %016lx R14: %016lx R15: %016lx\n",
269 regs->r13, regs->r14, regs->r15);
271 asm("mov %%ds,%0" : "=r" (ds));
272 asm("mov %%cs,%0" : "=r" (cs));
273 asm("mov %%es,%0" : "=r" (es));
274 asm("mov %%fs,%0" : "=r" (fsindex));
275 asm("mov %%gs,%0" : "=r" (gsindex));
277 rdmsrl(MSR_FS_BASE, fs);
278 rdmsrl(MSR_GS_BASE, gs);
279 rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
281 printk("FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
282 fs,fsindex,gs,gsindex,shadowgs);
283 printk("CS: %04x DS: %04x ES: %04x\n", cs, ds, es);
285 }
287 void show_regs(struct pt_regs *regs)
288 {
289 printk("CPU %d:", smp_processor_id());
290 __show_regs(regs);
291 show_trace(NULL, regs, (void *)(regs + 1));
292 }
294 /*
295 * Free current thread data structures etc..
296 */
297 void exit_thread(void)
298 {
299 struct task_struct *me = current;
300 struct thread_struct *t = &me->thread;
302 if (me->thread.io_bitmap_ptr) {
303 #ifndef CONFIG_X86_NO_TSS
304 struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
305 #endif
306 #ifdef CONFIG_XEN
307 struct physdev_set_iobitmap iobmp_op;
308 memset(&iobmp_op, 0, sizeof(iobmp_op));
309 #endif
311 kfree(t->io_bitmap_ptr);
312 t->io_bitmap_ptr = NULL;
313 /*
314 * Careful, clear this in the TSS too:
315 */
316 #ifndef CONFIG_X86_NO_TSS
317 memset(tss->io_bitmap, 0xff, t->io_bitmap_max);
318 put_cpu();
319 #endif
320 #ifdef CONFIG_XEN
321 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap,
322 &iobmp_op));
323 #endif
324 t->io_bitmap_max = 0;
325 }
326 }
328 void load_gs_index(unsigned gs)
329 {
330 WARN_ON(HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gs));
331 }
333 void flush_thread(void)
334 {
335 struct task_struct *tsk = current;
336 struct thread_info *t = current_thread_info();
338 if (t->flags & _TIF_ABI_PENDING) {
339 t->flags ^= (_TIF_ABI_PENDING | _TIF_IA32);
340 if (t->flags & _TIF_IA32)
341 current_thread_info()->status |= TS_COMPAT;
342 }
344 tsk->thread.debugreg0 = 0;
345 tsk->thread.debugreg1 = 0;
346 tsk->thread.debugreg2 = 0;
347 tsk->thread.debugreg3 = 0;
348 tsk->thread.debugreg6 = 0;
349 tsk->thread.debugreg7 = 0;
350 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
351 /*
352 * Forget coprocessor state..
353 */
354 clear_fpu(tsk);
355 clear_used_math();
356 }
358 void release_thread(struct task_struct *dead_task)
359 {
360 if (dead_task->mm) {
361 if (dead_task->mm->context.size) {
362 printk("WARNING: dead process %8s still has LDT? <%p/%d>\n",
363 dead_task->comm,
364 dead_task->mm->context.ldt,
365 dead_task->mm->context.size);
366 BUG();
367 }
368 }
369 }
371 static inline void set_32bit_tls(struct task_struct *t, int tls, u32 addr)
372 {
373 struct user_desc ud = {
374 .base_addr = addr,
375 .limit = 0xfffff,
376 .seg_32bit = 1,
377 .limit_in_pages = 1,
378 .useable = 1,
379 };
380 struct n_desc_struct *desc = (void *)t->thread.tls_array;
381 desc += tls;
382 desc->a = LDT_entry_a(&ud);
383 desc->b = LDT_entry_b(&ud);
384 }
386 static inline u32 read_32bit_tls(struct task_struct *t, int tls)
387 {
388 struct desc_struct *desc = (void *)t->thread.tls_array;
389 desc += tls;
390 return desc->base0 |
391 (((u32)desc->base1) << 16) |
392 (((u32)desc->base2) << 24);
393 }
395 /*
396 * This gets called before we allocate a new thread and copy
397 * the current task into it.
398 */
399 void prepare_to_copy(struct task_struct *tsk)
400 {
401 unlazy_fpu(tsk);
402 }
404 int copy_thread(int nr, unsigned long clone_flags, unsigned long rsp,
405 unsigned long unused,
406 struct task_struct * p, struct pt_regs * regs)
407 {
408 int err;
409 struct pt_regs * childregs;
410 struct task_struct *me = current;
412 childregs = ((struct pt_regs *)
413 (THREAD_SIZE + task_stack_page(p))) - 1;
414 *childregs = *regs;
416 childregs->rax = 0;
417 childregs->rsp = rsp;
418 if (rsp == ~0UL)
419 childregs->rsp = (unsigned long)childregs;
421 p->thread.rsp = (unsigned long) childregs;
422 p->thread.rsp0 = (unsigned long) (childregs+1);
423 p->thread.userrsp = me->thread.userrsp;
425 set_tsk_thread_flag(p, TIF_FORK);
427 p->thread.fs = me->thread.fs;
428 p->thread.gs = me->thread.gs;
430 asm("mov %%gs,%0" : "=m" (p->thread.gsindex));
431 asm("mov %%fs,%0" : "=m" (p->thread.fsindex));
432 asm("mov %%es,%0" : "=m" (p->thread.es));
433 asm("mov %%ds,%0" : "=m" (p->thread.ds));
435 if (unlikely(me->thread.io_bitmap_ptr != NULL)) {
436 p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
437 if (!p->thread.io_bitmap_ptr) {
438 p->thread.io_bitmap_max = 0;
439 return -ENOMEM;
440 }
441 memcpy(p->thread.io_bitmap_ptr, me->thread.io_bitmap_ptr,
442 IO_BITMAP_BYTES);
443 }
445 /*
446 * Set a new TLS for the child thread?
447 */
448 if (clone_flags & CLONE_SETTLS) {
449 #ifdef CONFIG_IA32_EMULATION
450 if (test_thread_flag(TIF_IA32))
451 err = ia32_child_tls(p, childregs);
452 else
453 #endif
454 err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8);
455 if (err)
456 goto out;
457 }
458 p->thread.iopl = current->thread.iopl;
460 err = 0;
461 out:
462 if (err && p->thread.io_bitmap_ptr) {
463 kfree(p->thread.io_bitmap_ptr);
464 p->thread.io_bitmap_max = 0;
465 }
466 return err;
467 }
469 static inline void __save_init_fpu( struct task_struct *tsk )
470 {
471 asm volatile( "rex64 ; fxsave %0 ; fnclex"
472 : "=m" (tsk->thread.i387.fxsave));
473 tsk->thread_info->status &= ~TS_USEDFPU;
474 }
476 /*
477 * switch_to(x,y) should switch tasks from x to y.
478 *
479 * This could still be optimized:
480 * - fold all the options into a flag word and test it with a single test.
481 * - could test fs/gs bitsliced
482 *
483 * Kprobes not supported here. Set the probe on schedule instead.
484 */
485 __kprobes struct task_struct *
486 __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
487 {
488 struct thread_struct *prev = &prev_p->thread,
489 *next = &next_p->thread;
490 int cpu = smp_processor_id();
491 #ifndef CONFIG_X86_NO_TSS
492 struct tss_struct *tss = &per_cpu(init_tss, cpu);
493 #endif
494 #if CONFIG_XEN_COMPAT > 0x030002
495 struct physdev_set_iopl iopl_op;
496 struct physdev_set_iobitmap iobmp_op;
497 #else
498 struct physdev_op _pdo[2], *pdo = _pdo;
499 #define iopl_op pdo->u.set_iopl
500 #define iobmp_op pdo->u.set_iobitmap
501 #endif
502 multicall_entry_t _mcl[8], *mcl = _mcl;
504 /*
505 * This is basically '__unlazy_fpu', except that we queue a
506 * multicall to indicate FPU task switch, rather than
507 * synchronously trapping to Xen.
508 * The AMD workaround requires it to be after DS reload, or
509 * after DS has been cleared, which we do in __prepare_arch_switch.
510 */
511 if (prev_p->thread_info->status & TS_USEDFPU) {
512 __save_init_fpu(prev_p); /* _not_ save_init_fpu() */
513 mcl->op = __HYPERVISOR_fpu_taskswitch;
514 mcl->args[0] = 1;
515 mcl++;
516 }
518 /*
519 * Reload esp0, LDT and the page table pointer:
520 */
521 mcl->op = __HYPERVISOR_stack_switch;
522 mcl->args[0] = __KERNEL_DS;
523 mcl->args[1] = next->rsp0;
524 mcl++;
526 /*
527 * Load the per-thread Thread-Local Storage descriptor.
528 * This is load_TLS(next, cpu) with multicalls.
529 */
530 #define C(i) do { \
531 if (unlikely(next->tls_array[i] != prev->tls_array[i])) { \
532 mcl->op = __HYPERVISOR_update_descriptor; \
533 mcl->args[0] = virt_to_machine( \
534 &cpu_gdt(cpu)[GDT_ENTRY_TLS_MIN + i]); \
535 mcl->args[1] = next->tls_array[i]; \
536 mcl++; \
537 } \
538 } while (0)
539 C(0); C(1); C(2);
540 #undef C
542 if (unlikely(prev->iopl != next->iopl)) {
543 iopl_op.iopl = (next->iopl == 0) ? 1 : next->iopl;
544 #if CONFIG_XEN_COMPAT > 0x030002
545 mcl->op = __HYPERVISOR_physdev_op;
546 mcl->args[0] = PHYSDEVOP_set_iopl;
547 mcl->args[1] = (unsigned long)&iopl_op;
548 #else
549 mcl->op = __HYPERVISOR_physdev_op_compat;
550 pdo->cmd = PHYSDEVOP_set_iopl;
551 mcl->args[0] = (unsigned long)pdo++;
552 #endif
553 mcl++;
554 }
556 if (unlikely(prev->io_bitmap_ptr || next->io_bitmap_ptr)) {
557 set_xen_guest_handle(iobmp_op.bitmap,
558 (char *)next->io_bitmap_ptr);
559 iobmp_op.nr_ports = next->io_bitmap_ptr ? IO_BITMAP_BITS : 0;
560 #if CONFIG_XEN_COMPAT > 0x030002
561 mcl->op = __HYPERVISOR_physdev_op;
562 mcl->args[0] = PHYSDEVOP_set_iobitmap;
563 mcl->args[1] = (unsigned long)&iobmp_op;
564 #else
565 mcl->op = __HYPERVISOR_physdev_op_compat;
566 pdo->cmd = PHYSDEVOP_set_iobitmap;
567 mcl->args[0] = (unsigned long)pdo++;
568 #endif
569 mcl++;
570 }
572 #if CONFIG_XEN_COMPAT <= 0x030002
573 BUG_ON(pdo > _pdo + ARRAY_SIZE(_pdo));
574 #endif
575 BUG_ON(mcl > _mcl + ARRAY_SIZE(_mcl));
576 if (unlikely(HYPERVISOR_multicall_check(_mcl, mcl - _mcl, NULL)))
577 BUG();
579 /*
580 * Switch DS and ES.
581 * This won't pick up thread selector changes, but I guess that is ok.
582 */
583 if (unlikely(next->es))
584 loadsegment(es, next->es);
586 if (unlikely(next->ds))
587 loadsegment(ds, next->ds);
589 /*
590 * Switch FS and GS.
591 */
592 if (unlikely(next->fsindex))
593 loadsegment(fs, next->fsindex);
595 if (next->fs)
596 WARN_ON(HYPERVISOR_set_segment_base(SEGBASE_FS, next->fs));
598 if (unlikely(next->gsindex))
599 load_gs_index(next->gsindex);
601 if (next->gs)
602 WARN_ON(HYPERVISOR_set_segment_base(SEGBASE_GS_USER, next->gs));
604 /*
605 * Switch the PDA context.
606 */
607 prev->userrsp = read_pda(oldrsp);
608 write_pda(oldrsp, next->userrsp);
609 write_pda(pcurrent, next_p);
610 write_pda(kernelstack,
611 task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);
613 /*
614 * Now maybe reload the debug registers
615 */
616 if (unlikely(next->debugreg7)) {
617 set_debugreg(next->debugreg0, 0);
618 set_debugreg(next->debugreg1, 1);
619 set_debugreg(next->debugreg2, 2);
620 set_debugreg(next->debugreg3, 3);
621 /* no 4 and 5 */
622 set_debugreg(next->debugreg6, 6);
623 set_debugreg(next->debugreg7, 7);
624 }
626 return prev_p;
627 }
629 /*
630 * sys_execve() executes a new program.
631 */
632 asmlinkage
633 long sys_execve(char __user *name, char __user * __user *argv,
634 char __user * __user *envp, struct pt_regs regs)
635 {
636 long error;
637 char * filename;
639 filename = getname(name);
640 error = PTR_ERR(filename);
641 if (IS_ERR(filename))
642 return error;
643 error = do_execve(filename, argv, envp, &regs);
644 if (error == 0) {
645 task_lock(current);
646 current->ptrace &= ~PT_DTRACE;
647 task_unlock(current);
648 }
649 putname(filename);
650 return error;
651 }
653 void set_personality_64bit(void)
654 {
655 /* inherit personality from parent */
657 /* Make sure to be in 64bit mode */
658 clear_thread_flag(TIF_IA32);
660 /* TBD: overwrites user setup. Should have two bits.
661 But 64bit processes have always behaved this way,
662 so it's not too bad. The main problem is just that
663 32bit childs are affected again. */
664 current->personality &= ~READ_IMPLIES_EXEC;
665 }
667 asmlinkage long sys_fork(struct pt_regs *regs)
668 {
669 return do_fork(SIGCHLD, regs->rsp, regs, 0, NULL, NULL);
670 }
672 asmlinkage long
673 sys_clone(unsigned long clone_flags, unsigned long newsp,
674 void __user *parent_tid, void __user *child_tid, struct pt_regs *regs)
675 {
676 if (!newsp)
677 newsp = regs->rsp;
678 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
679 }
681 /*
682 * This is trivial, and on the face of it looks like it
683 * could equally well be done in user mode.
684 *
685 * Not so, for quite unobvious reasons - register pressure.
686 * In user mode vfork() cannot have a stack frame, and if
687 * done by calling the "clone()" system call directly, you
688 * do not have enough call-clobbered registers to hold all
689 * the information you need.
690 */
691 asmlinkage long sys_vfork(struct pt_regs *regs)
692 {
693 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->rsp, regs, 0,
694 NULL, NULL);
695 }
697 unsigned long get_wchan(struct task_struct *p)
698 {
699 unsigned long stack;
700 u64 fp,rip;
701 int count = 0;
703 if (!p || p == current || p->state==TASK_RUNNING)
704 return 0;
705 stack = (unsigned long)task_stack_page(p);
706 if (p->thread.rsp < stack || p->thread.rsp > stack+THREAD_SIZE)
707 return 0;
708 fp = *(u64 *)(p->thread.rsp);
709 do {
710 if (fp < (unsigned long)stack ||
711 fp > (unsigned long)stack+THREAD_SIZE)
712 return 0;
713 rip = *(u64 *)(fp+8);
714 if (!in_sched_functions(rip))
715 return rip;
716 fp = *(u64 *)fp;
717 } while (count++ < 16);
718 return 0;
719 }
721 long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
722 {
723 int ret = 0;
724 int doit = task == current;
725 int cpu;
727 switch (code) {
728 case ARCH_SET_GS:
729 if (addr >= TASK_SIZE_OF(task))
730 return -EPERM;
731 cpu = get_cpu();
732 /* handle small bases via the GDT because that's faster to
733 switch. */
734 if (addr <= 0xffffffff) {
735 set_32bit_tls(task, GS_TLS, addr);
736 if (doit) {
737 load_TLS(&task->thread, cpu);
738 load_gs_index(GS_TLS_SEL);
739 }
740 task->thread.gsindex = GS_TLS_SEL;
741 task->thread.gs = 0;
742 } else {
743 task->thread.gsindex = 0;
744 task->thread.gs = addr;
745 if (doit) {
746 load_gs_index(0);
747 ret = HYPERVISOR_set_segment_base(
748 SEGBASE_GS_USER, addr);
749 }
750 }
751 put_cpu();
752 break;
753 case ARCH_SET_FS:
754 /* Not strictly needed for fs, but do it for symmetry
755 with gs */
756 if (addr >= TASK_SIZE_OF(task))
757 return -EPERM;
758 cpu = get_cpu();
759 /* handle small bases via the GDT because that's faster to
760 switch. */
761 if (addr <= 0xffffffff) {
762 set_32bit_tls(task, FS_TLS, addr);
763 if (doit) {
764 load_TLS(&task->thread, cpu);
765 asm volatile("movl %0,%%fs" :: "r"(FS_TLS_SEL));
766 }
767 task->thread.fsindex = FS_TLS_SEL;
768 task->thread.fs = 0;
769 } else {
770 task->thread.fsindex = 0;
771 task->thread.fs = addr;
772 if (doit) {
773 /* set the selector to 0 to not confuse
774 __switch_to */
775 asm volatile("movl %0,%%fs" :: "r" (0));
776 ret = HYPERVISOR_set_segment_base(SEGBASE_FS,
777 addr);
778 }
779 }
780 put_cpu();
781 break;
782 case ARCH_GET_FS: {
783 unsigned long base;
784 if (task->thread.fsindex == FS_TLS_SEL)
785 base = read_32bit_tls(task, FS_TLS);
786 else if (doit)
787 rdmsrl(MSR_FS_BASE, base);
788 else
789 base = task->thread.fs;
790 ret = put_user(base, (unsigned long __user *)addr);
791 break;
792 }
793 case ARCH_GET_GS: {
794 unsigned long base;
795 unsigned gsindex;
796 if (task->thread.gsindex == GS_TLS_SEL)
797 base = read_32bit_tls(task, GS_TLS);
798 else if (doit) {
799 asm("movl %%gs,%0" : "=r" (gsindex));
800 if (gsindex)
801 rdmsrl(MSR_KERNEL_GS_BASE, base);
802 else
803 base = task->thread.gs;
804 }
805 else
806 base = task->thread.gs;
807 ret = put_user(base, (unsigned long __user *)addr);
808 break;
809 }
811 default:
812 ret = -EINVAL;
813 break;
814 }
816 return ret;
817 }
819 long sys_arch_prctl(int code, unsigned long addr)
820 {
821 return do_arch_prctl(current, code, addr);
822 }
824 /*
825 * Capture the user space registers if the task is not running (in user space)
826 */
827 int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
828 {
829 struct pt_regs *pp, ptregs;
831 pp = task_pt_regs(tsk);
833 ptregs = *pp;
834 ptregs.cs &= 0xffff;
835 ptregs.ss &= 0xffff;
837 elf_core_copy_regs(regs, &ptregs);
839 boot_option_idle_override = 1;
840 return 1;
841 }
843 unsigned long arch_align_stack(unsigned long sp)
844 {
845 if (randomize_va_space)
846 sp -= get_random_int() % 8192;
847 return sp & ~0xf;
848 }