process_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. *
  4. * Pentium III FXSR, SSE support
  5. * Gareth Hughes <gareth@valinux.com>, May 2000
  6. *
  7. * X86-64 port
  8. * Andi Kleen.
  9. *
  10. * CPU hotplug support - ashok.raj@intel.com
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of process handling..
  14. */
  15. #include <linux/cpu.h>
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/fs.h>
  19. #include <linux/kernel.h>
  20. #include <linux/mm.h>
  21. #include <linux/elfcore.h>
  22. #include <linux/smp.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/export.h>
  28. #include <linux/ptrace.h>
  29. #include <linux/notifier.h>
  30. #include <linux/kprobes.h>
  31. #include <linux/kdebug.h>
  32. #include <linux/prctl.h>
  33. #include <linux/uaccess.h>
  34. #include <linux/io.h>
  35. #include <linux/ftrace.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/processor.h>
  38. #include <asm/fpu/internal.h>
  39. #include <asm/mmu_context.h>
  40. #include <asm/prctl.h>
  41. #include <asm/desc.h>
  42. #include <asm/proto.h>
  43. #include <asm/ia32.h>
  44. #include <asm/idle.h>
  45. #include <asm/syscalls.h>
  46. #include <asm/debugreg.h>
  47. #include <asm/switch_to.h>
  48. #include <asm/xen/hypervisor.h>
  49. #include <asm/vdso.h>
  50. __visible DEFINE_PER_CPU(unsigned long, rsp_scratch);
  51. /* Prints also some state that isn't saved in the pt_regs */
  52. void __show_regs(struct pt_regs *regs, int all)
  53. {
  54. unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
  55. unsigned long d0, d1, d2, d3, d6, d7;
  56. unsigned int fsindex, gsindex;
  57. unsigned int ds, cs, es;
  58. printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
  59. printk_address(regs->ip);
  60. printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss,
  61. regs->sp, regs->flags);
  62. printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
  63. regs->ax, regs->bx, regs->cx);
  64. printk(KERN_DEFAULT "RDX: %016lx RSI: %016lx RDI: %016lx\n",
  65. regs->dx, regs->si, regs->di);
  66. printk(KERN_DEFAULT "RBP: %016lx R08: %016lx R09: %016lx\n",
  67. regs->bp, regs->r8, regs->r9);
  68. printk(KERN_DEFAULT "R10: %016lx R11: %016lx R12: %016lx\n",
  69. regs->r10, regs->r11, regs->r12);
  70. printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
  71. regs->r13, regs->r14, regs->r15);
  72. asm("movl %%ds,%0" : "=r" (ds));
  73. asm("movl %%cs,%0" : "=r" (cs));
  74. asm("movl %%es,%0" : "=r" (es));
  75. asm("movl %%fs,%0" : "=r" (fsindex));
  76. asm("movl %%gs,%0" : "=r" (gsindex));
  77. rdmsrl(MSR_FS_BASE, fs);
  78. rdmsrl(MSR_GS_BASE, gs);
  79. rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
  80. if (!all)
  81. return;
  82. cr0 = read_cr0();
  83. cr2 = read_cr2();
  84. cr3 = read_cr3();
  85. cr4 = __read_cr4();
  86. printk(KERN_DEFAULT "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
  87. fs, fsindex, gs, gsindex, shadowgs);
  88. printk(KERN_DEFAULT "CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
  89. es, cr0);
  90. printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
  91. cr4);
  92. get_debugreg(d0, 0);
  93. get_debugreg(d1, 1);
  94. get_debugreg(d2, 2);
  95. get_debugreg(d3, 3);
  96. get_debugreg(d6, 6);
  97. get_debugreg(d7, 7);
  98. /* Only print out debug registers if they are in their non-default state. */
  99. if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
  100. (d6 == DR6_RESERVED) && (d7 == 0x400))) {
  101. printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n",
  102. d0, d1, d2);
  103. printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n",
  104. d3, d6, d7);
  105. }
  106. if (boot_cpu_has(X86_FEATURE_OSPKE))
  107. printk(KERN_DEFAULT "PKRU: %08x\n", read_pkru());
  108. }
  109. void release_thread(struct task_struct *dead_task)
  110. {
  111. if (dead_task->mm) {
  112. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  113. if (dead_task->mm->context.ldt) {
  114. pr_warn("WARNING: dead process %s still has LDT? <%p/%d>\n",
  115. dead_task->comm,
  116. dead_task->mm->context.ldt->entries,
  117. dead_task->mm->context.ldt->size);
  118. BUG();
  119. }
  120. #endif
  121. }
  122. }
  123. enum which_selector {
  124. FS,
  125. GS
  126. };
  127. /*
  128. * Saves the FS or GS base for an outgoing thread if FSGSBASE extensions are
  129. * not available. The goal is to be reasonably fast on non-FSGSBASE systems.
  130. * It's forcibly inlined because it'll generate better code and this function
  131. * is hot.
  132. */
  133. static __always_inline void save_base_legacy(struct task_struct *prev_p,
  134. unsigned short selector,
  135. enum which_selector which)
  136. {
  137. if (likely(selector == 0)) {
  138. /*
  139. * On Intel (without X86_BUG_NULL_SEG), the segment base could
  140. * be the pre-existing saved base or it could be zero. On AMD
  141. * (with X86_BUG_NULL_SEG), the segment base could be almost
  142. * anything.
  143. *
  144. * This branch is very hot (it's hit twice on almost every
  145. * context switch between 64-bit programs), and avoiding
  146. * the RDMSR helps a lot, so we just assume that whatever
  147. * value is already saved is correct. This matches historical
  148. * Linux behavior, so it won't break existing applications.
  149. *
  150. * To avoid leaking state, on non-X86_BUG_NULL_SEG CPUs, if we
  151. * report that the base is zero, it needs to actually be zero:
  152. * see the corresponding logic in load_seg_legacy.
  153. */
  154. } else {
  155. /*
  156. * If the selector is 1, 2, or 3, then the base is zero on
  157. * !X86_BUG_NULL_SEG CPUs and could be anything on
  158. * X86_BUG_NULL_SEG CPUs. In the latter case, Linux
  159. * has never attempted to preserve the base across context
  160. * switches.
  161. *
  162. * If selector > 3, then it refers to a real segment, and
  163. * saving the base isn't necessary.
  164. */
  165. if (which == FS)
  166. prev_p->thread.fsbase = 0;
  167. else
  168. prev_p->thread.gsbase = 0;
  169. }
  170. }
  171. static __always_inline void save_fsgs(struct task_struct *task)
  172. {
  173. savesegment(fs, task->thread.fsindex);
  174. savesegment(gs, task->thread.gsindex);
  175. save_base_legacy(task, task->thread.fsindex, FS);
  176. save_base_legacy(task, task->thread.gsindex, GS);
  177. }
  178. static __always_inline void loadseg(enum which_selector which,
  179. unsigned short sel)
  180. {
  181. if (which == FS)
  182. loadsegment(fs, sel);
  183. else
  184. load_gs_index(sel);
  185. }
  186. static __always_inline void load_seg_legacy(unsigned short prev_index,
  187. unsigned long prev_base,
  188. unsigned short next_index,
  189. unsigned long next_base,
  190. enum which_selector which)
  191. {
  192. if (likely(next_index <= 3)) {
  193. /*
  194. * The next task is using 64-bit TLS, is not using this
  195. * segment at all, or is having fun with arcane CPU features.
  196. */
  197. if (next_base == 0) {
  198. /*
  199. * Nasty case: on AMD CPUs, we need to forcibly zero
  200. * the base.
  201. */
  202. if (static_cpu_has_bug(X86_BUG_NULL_SEG)) {
  203. loadseg(which, __USER_DS);
  204. loadseg(which, next_index);
  205. } else {
  206. /*
  207. * We could try to exhaustively detect cases
  208. * under which we can skip the segment load,
  209. * but there's really only one case that matters
  210. * for performance: if both the previous and
  211. * next states are fully zeroed, we can skip
  212. * the load.
  213. *
  214. * (This assumes that prev_base == 0 has no
  215. * false positives. This is the case on
  216. * Intel-style CPUs.)
  217. */
  218. if (likely(prev_index | next_index | prev_base))
  219. loadseg(which, next_index);
  220. }
  221. } else {
  222. if (prev_index != next_index)
  223. loadseg(which, next_index);
  224. wrmsrl(which == FS ? MSR_FS_BASE : MSR_KERNEL_GS_BASE,
  225. next_base);
  226. }
  227. } else {
  228. /*
  229. * The next task is using a real segment. Loading the selector
  230. * is sufficient.
  231. */
  232. loadseg(which, next_index);
  233. }
  234. }
  235. int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
  236. unsigned long arg, struct task_struct *p, unsigned long tls)
  237. {
  238. int err;
  239. struct pt_regs *childregs;
  240. struct fork_frame *fork_frame;
  241. struct inactive_task_frame *frame;
  242. struct task_struct *me = current;
  243. p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  244. childregs = task_pt_regs(p);
  245. fork_frame = container_of(childregs, struct fork_frame, regs);
  246. frame = &fork_frame->frame;
  247. frame->bp = 0;
  248. frame->ret_addr = (unsigned long) ret_from_fork;
  249. p->thread.sp = (unsigned long) fork_frame;
  250. p->thread.io_bitmap_ptr = NULL;
  251. savesegment(gs, p->thread.gsindex);
  252. p->thread.gsbase = p->thread.gsindex ? 0 : me->thread.gsbase;
  253. savesegment(fs, p->thread.fsindex);
  254. p->thread.fsbase = p->thread.fsindex ? 0 : me->thread.fsbase;
  255. savesegment(es, p->thread.es);
  256. savesegment(ds, p->thread.ds);
  257. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  258. if (unlikely(p->flags & PF_KTHREAD)) {
  259. /* kernel thread */
  260. memset(childregs, 0, sizeof(struct pt_regs));
  261. frame->bx = sp; /* function */
  262. frame->r12 = arg;
  263. return 0;
  264. }
  265. frame->bx = 0;
  266. *childregs = *current_pt_regs();
  267. childregs->ax = 0;
  268. if (sp)
  269. childregs->sp = sp;
  270. err = -ENOMEM;
  271. if (unlikely(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
  272. p->thread.io_bitmap_ptr = kmemdup(me->thread.io_bitmap_ptr,
  273. IO_BITMAP_BYTES, GFP_KERNEL);
  274. if (!p->thread.io_bitmap_ptr) {
  275. p->thread.io_bitmap_max = 0;
  276. return -ENOMEM;
  277. }
  278. set_tsk_thread_flag(p, TIF_IO_BITMAP);
  279. }
  280. /*
  281. * Set a new TLS for the child thread?
  282. */
  283. if (clone_flags & CLONE_SETTLS) {
  284. #ifdef CONFIG_IA32_EMULATION
  285. if (in_ia32_syscall())
  286. err = do_set_thread_area(p, -1,
  287. (struct user_desc __user *)tls, 0);
  288. else
  289. #endif
  290. err = do_arch_prctl(p, ARCH_SET_FS, tls);
  291. if (err)
  292. goto out;
  293. }
  294. err = 0;
  295. out:
  296. if (err && p->thread.io_bitmap_ptr) {
  297. kfree(p->thread.io_bitmap_ptr);
  298. p->thread.io_bitmap_max = 0;
  299. }
  300. return err;
  301. }
  302. static void
  303. start_thread_common(struct pt_regs *regs, unsigned long new_ip,
  304. unsigned long new_sp,
  305. unsigned int _cs, unsigned int _ss, unsigned int _ds)
  306. {
  307. WARN_ON_ONCE(regs != current_pt_regs());
  308. if (static_cpu_has(X86_BUG_NULL_SEG)) {
  309. /* Loading zero below won't clear the base. */
  310. loadsegment(fs, __USER_DS);
  311. load_gs_index(__USER_DS);
  312. }
  313. loadsegment(fs, 0);
  314. loadsegment(es, _ds);
  315. loadsegment(ds, _ds);
  316. load_gs_index(0);
  317. regs->ip = new_ip;
  318. regs->sp = new_sp;
  319. regs->cs = _cs;
  320. regs->ss = _ss;
  321. regs->flags = X86_EFLAGS_IF;
  322. force_iret();
  323. }
  324. void
  325. start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  326. {
  327. start_thread_common(regs, new_ip, new_sp,
  328. __USER_CS, __USER_DS, 0);
  329. }
  330. #ifdef CONFIG_COMPAT
  331. void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)
  332. {
  333. start_thread_common(regs, new_ip, new_sp,
  334. test_thread_flag(TIF_X32)
  335. ? __USER_CS : __USER32_CS,
  336. __USER_DS, __USER_DS);
  337. }
  338. #endif
  339. /*
  340. * switch_to(x,y) should switch tasks from x to y.
  341. *
  342. * This could still be optimized:
  343. * - fold all the options into a flag word and test it with a single test.
  344. * - could test fs/gs bitsliced
  345. *
  346. * Kprobes not supported here. Set the probe on schedule instead.
  347. * Function graph tracer not supported too.
  348. */
  349. __visible __notrace_funcgraph struct task_struct *
  350. __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  351. {
  352. struct thread_struct *prev = &prev_p->thread;
  353. struct thread_struct *next = &next_p->thread;
  354. struct fpu *prev_fpu = &prev->fpu;
  355. struct fpu *next_fpu = &next->fpu;
  356. int cpu = smp_processor_id();
  357. struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
  358. fpu_switch_t fpu_switch;
  359. fpu_switch = switch_fpu_prepare(prev_fpu, next_fpu, cpu);
  360. /* We must save %fs and %gs before load_TLS() because
  361. * %fs and %gs may be cleared by load_TLS().
  362. *
  363. * (e.g. xen_load_tls())
  364. */
  365. save_fsgs(prev_p);
  366. /*
  367. * Load TLS before restoring any segments so that segment loads
  368. * reference the correct GDT entries.
  369. */
  370. load_TLS(next, cpu);
  371. /*
  372. * Leave lazy mode, flushing any hypercalls made here. This
  373. * must be done after loading TLS entries in the GDT but before
  374. * loading segments that might reference them, and and it must
  375. * be done before fpu__restore(), so the TS bit is up to
  376. * date.
  377. */
  378. arch_end_context_switch(next_p);
  379. /* Switch DS and ES.
  380. *
  381. * Reading them only returns the selectors, but writing them (if
  382. * nonzero) loads the full descriptor from the GDT or LDT. The
  383. * LDT for next is loaded in switch_mm, and the GDT is loaded
  384. * above.
  385. *
  386. * We therefore need to write new values to the segment
  387. * registers on every context switch unless both the new and old
  388. * values are zero.
  389. *
  390. * Note that we don't need to do anything for CS and SS, as
  391. * those are saved and restored as part of pt_regs.
  392. */
  393. savesegment(es, prev->es);
  394. if (unlikely(next->es | prev->es))
  395. loadsegment(es, next->es);
  396. savesegment(ds, prev->ds);
  397. if (unlikely(next->ds | prev->ds))
  398. loadsegment(ds, next->ds);
  399. load_seg_legacy(prev->fsindex, prev->fsbase,
  400. next->fsindex, next->fsbase, FS);
  401. load_seg_legacy(prev->gsindex, prev->gsbase,
  402. next->gsindex, next->gsbase, GS);
  403. switch_fpu_finish(next_fpu, fpu_switch);
  404. /*
  405. * Switch the PDA and FPU contexts.
  406. */
  407. this_cpu_write(current_task, next_p);
  408. /* Reload esp0 and ss1. This changes current_thread_info(). */
  409. load_sp0(tss, next);
  410. /*
  411. * Now maybe reload the debug registers and handle I/O bitmaps
  412. */
  413. if (unlikely(task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT ||
  414. task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))
  415. __switch_to_xtra(prev_p, next_p, tss);
  416. #ifdef CONFIG_XEN
  417. /*
  418. * On Xen PV, IOPL bits in pt_regs->flags have no effect, and
  419. * current_pt_regs()->flags may not match the current task's
  420. * intended IOPL. We need to switch it manually.
  421. */
  422. if (unlikely(static_cpu_has(X86_FEATURE_XENPV) &&
  423. prev->iopl != next->iopl))
  424. xen_set_iopl_mask(next->iopl);
  425. #endif
  426. if (static_cpu_has_bug(X86_BUG_SYSRET_SS_ATTRS)) {
  427. /*
  428. * AMD CPUs have a misfeature: SYSRET sets the SS selector but
  429. * does not update the cached descriptor. As a result, if we
  430. * do SYSRET while SS is NULL, we'll end up in user mode with
  431. * SS apparently equal to __USER_DS but actually unusable.
  432. *
  433. * The straightforward workaround would be to fix it up just
  434. * before SYSRET, but that would slow down the system call
  435. * fast paths. Instead, we ensure that SS is never NULL in
  436. * system call context. We do this by replacing NULL SS
  437. * selectors at every context switch. SYSCALL sets up a valid
  438. * SS, so the only way to get NULL is to re-enter the kernel
  439. * from CPL 3 through an interrupt. Since that can't happen
  440. * in the same task as a running syscall, we are guaranteed to
  441. * context switch between every interrupt vector entry and a
  442. * subsequent SYSRET.
  443. *
  444. * We read SS first because SS reads are much faster than
  445. * writes. Out of caution, we force SS to __KERNEL_DS even if
  446. * it previously had a different non-NULL value.
  447. */
  448. unsigned short ss_sel;
  449. savesegment(ss, ss_sel);
  450. if (ss_sel != __KERNEL_DS)
  451. loadsegment(ss, __KERNEL_DS);
  452. }
  453. return prev_p;
  454. }
  455. void set_personality_64bit(void)
  456. {
  457. /* inherit personality from parent */
  458. /* Make sure to be in 64bit mode */
  459. clear_thread_flag(TIF_IA32);
  460. clear_thread_flag(TIF_ADDR32);
  461. clear_thread_flag(TIF_X32);
  462. /* Ensure the corresponding mm is not marked. */
  463. if (current->mm)
  464. current->mm->context.ia32_compat = 0;
  465. /* TBD: overwrites user setup. Should have two bits.
  466. But 64bit processes have always behaved this way,
  467. so it's not too bad. The main problem is just that
  468. 32bit childs are affected again. */
  469. current->personality &= ~READ_IMPLIES_EXEC;
  470. }
  471. void set_personality_ia32(bool x32)
  472. {
  473. /* inherit personality from parent */
  474. /* Make sure to be in 32bit mode */
  475. set_thread_flag(TIF_ADDR32);
  476. /* Mark the associated mm as containing 32-bit tasks. */
  477. if (x32) {
  478. clear_thread_flag(TIF_IA32);
  479. set_thread_flag(TIF_X32);
  480. if (current->mm)
  481. current->mm->context.ia32_compat = TIF_X32;
  482. current->personality &= ~READ_IMPLIES_EXEC;
  483. /* in_compat_syscall() uses the presence of the x32
  484. syscall bit flag to determine compat status */
  485. current_thread_info()->status &= ~TS_COMPAT;
  486. } else {
  487. set_thread_flag(TIF_IA32);
  488. clear_thread_flag(TIF_X32);
  489. if (current->mm)
  490. current->mm->context.ia32_compat = TIF_IA32;
  491. current->personality |= force_personality32;
  492. /* Prepare the first "return" to user space */
  493. current_thread_info()->status |= TS_COMPAT;
  494. }
  495. }
  496. EXPORT_SYMBOL_GPL(set_personality_ia32);
  497. #ifdef CONFIG_CHECKPOINT_RESTORE
  498. static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr)
  499. {
  500. int ret;
  501. ret = map_vdso_once(image, addr);
  502. if (ret)
  503. return ret;
  504. return (long)image->size;
  505. }
  506. #endif
  507. long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
  508. {
  509. int ret = 0;
  510. int doit = task == current;
  511. int cpu;
  512. switch (code) {
  513. case ARCH_SET_GS:
  514. if (addr >= TASK_SIZE_MAX)
  515. return -EPERM;
  516. cpu = get_cpu();
  517. task->thread.gsindex = 0;
  518. task->thread.gsbase = addr;
  519. if (doit) {
  520. load_gs_index(0);
  521. ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, addr);
  522. }
  523. put_cpu();
  524. break;
  525. case ARCH_SET_FS:
  526. /* Not strictly needed for fs, but do it for symmetry
  527. with gs */
  528. if (addr >= TASK_SIZE_MAX)
  529. return -EPERM;
  530. cpu = get_cpu();
  531. task->thread.fsindex = 0;
  532. task->thread.fsbase = addr;
  533. if (doit) {
  534. /* set the selector to 0 to not confuse __switch_to */
  535. loadsegment(fs, 0);
  536. ret = wrmsrl_safe(MSR_FS_BASE, addr);
  537. }
  538. put_cpu();
  539. break;
  540. case ARCH_GET_FS: {
  541. unsigned long base;
  542. if (doit)
  543. rdmsrl(MSR_FS_BASE, base);
  544. else
  545. base = task->thread.fsbase;
  546. ret = put_user(base, (unsigned long __user *)addr);
  547. break;
  548. }
  549. case ARCH_GET_GS: {
  550. unsigned long base;
  551. if (doit)
  552. rdmsrl(MSR_KERNEL_GS_BASE, base);
  553. else
  554. base = task->thread.gsbase;
  555. ret = put_user(base, (unsigned long __user *)addr);
  556. break;
  557. }
  558. #ifdef CONFIG_CHECKPOINT_RESTORE
  559. # ifdef CONFIG_X86_X32_ABI
  560. case ARCH_MAP_VDSO_X32:
  561. return prctl_map_vdso(&vdso_image_x32, addr);
  562. # endif
  563. # if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
  564. case ARCH_MAP_VDSO_32:
  565. return prctl_map_vdso(&vdso_image_32, addr);
  566. # endif
  567. case ARCH_MAP_VDSO_64:
  568. return prctl_map_vdso(&vdso_image_64, addr);
  569. #endif
  570. default:
  571. ret = -EINVAL;
  572. break;
  573. }
  574. return ret;
  575. }
  576. long sys_arch_prctl(int code, unsigned long addr)
  577. {
  578. return do_arch_prctl(current, code, addr);
  579. }
  580. unsigned long KSTK_ESP(struct task_struct *task)
  581. {
  582. return task_pt_regs(task)->sp;
  583. }