2019-05-19 12:08:55 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
*
|
|
|
|
* Pentium III FXSR, SSE support
|
|
|
|
* Gareth Hughes <gareth@valinux.com>, May 2000
|
2008-01-30 12:31:03 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00:00
|
|
|
* X86-64 port
|
|
|
|
* Andi Kleen.
|
2005-06-25 21:55:00 +00:00
|
|
|
*
|
|
|
|
* CPU hotplug support - ashok.raj@intel.com
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file handles the architecture-dependent parts of process handling..
|
|
|
|
*/
|
|
|
|
|
2005-06-25 21:55:00 +00:00
|
|
|
#include <linux/cpu.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-08 17:51:36 +00:00
|
|
|
#include <linux/sched/task.h>
|
2017-02-08 17:51:37 +00:00
|
|
|
#include <linux/sched/task_stack.h>
|
2008-01-30 12:31:03 +00:00
|
|
|
#include <linux/fs.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/elfcore.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/user.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
2016-07-14 00:18:56 +00:00
|
|
|
#include <linux/export.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/ptrace.h>
|
2006-01-11 21:44:36 +00:00
|
|
|
#include <linux/notifier.h>
|
2006-03-26 09:38:20 +00:00
|
|
|
#include <linux/kprobes.h>
|
2007-05-08 07:27:03 +00:00
|
|
|
#include <linux/kdebug.h>
|
2008-04-13 22:24:18 +00:00
|
|
|
#include <linux/prctl.h>
|
2008-07-29 05:48:51 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/io.h>
|
2008-12-06 02:40:00 +00:00
|
|
|
#include <linux/ftrace.h>
|
2017-03-20 08:16:21 +00:00
|
|
|
#include <linux/syscalls.h>
|
2023-04-30 20:00:38 +00:00
|
|
|
#include <linux/iommu.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/processor.h>
|
2021-06-23 12:02:05 +00:00
|
|
|
#include <asm/pkru.h>
|
2021-10-15 01:16:20 +00:00
|
|
|
#include <asm/fpu/sched.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/prctl.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/ia32.h>
|
2009-06-01 18:14:55 +00:00
|
|
|
#include <asm/debugreg.h>
|
2012-03-28 17:11:12 +00:00
|
|
|
#include <asm/switch_to.h>
|
2016-03-16 21:14:21 +00:00
|
|
|
#include <asm/xen/hypervisor.h>
|
2016-09-05 13:33:05 +00:00
|
|
|
#include <asm/vdso.h>
|
2020-05-05 22:36:12 +00:00
|
|
|
#include <asm/resctrl.h>
|
2017-03-31 11:11:37 +00:00
|
|
|
#include <asm/unistd.h>
|
2018-09-18 23:08:53 +00:00
|
|
|
#include <asm/fsgsbase.h>
|
2017-03-31 11:11:37 +00:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
|
|
|
/* Not included via unistd.h */
|
|
|
|
#include <asm/unistd_32_ia32.h>
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-11-25 18:33:47 +00:00
|
|
|
#include "process.h"
|
|
|
|
|
2008-01-30 12:31:03 +00:00
|
|
|
/* Prints also some state that isn't saved in the pt_regs */
|
2020-06-29 14:48:46 +00:00
|
|
|
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
|
|
|
|
const char *log_lvl)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
|
2007-07-21 15:10:42 +00:00
|
|
|
unsigned long d0, d1, d2, d3, d6, d7;
|
2008-01-30 12:31:03 +00:00
|
|
|
unsigned int fsindex, gsindex;
|
2018-11-21 23:11:24 +00:00
|
|
|
unsigned int ds, es;
|
2009-12-08 08:29:42 +00:00
|
|
|
|
2020-06-29 14:48:46 +00:00
|
|
|
show_iret_regs(regs, log_lvl);
|
2017-12-04 14:07:09 +00:00
|
|
|
|
2016-10-20 16:34:45 +00:00
|
|
|
if (regs->orig_ax != -1)
|
|
|
|
pr_cont(" ORIG_RAX: %016lx\n", regs->orig_ax);
|
|
|
|
else
|
|
|
|
pr_cont("\n");
|
|
|
|
|
2020-06-29 14:48:46 +00:00
|
|
|
printk("%sRAX: %016lx RBX: %016lx RCX: %016lx\n",
|
|
|
|
log_lvl, regs->ax, regs->bx, regs->cx);
|
|
|
|
printk("%sRDX: %016lx RSI: %016lx RDI: %016lx\n",
|
|
|
|
log_lvl, regs->dx, regs->si, regs->di);
|
|
|
|
printk("%sRBP: %016lx R08: %016lx R09: %016lx\n",
|
|
|
|
log_lvl, regs->bp, regs->r8, regs->r9);
|
|
|
|
printk("%sR10: %016lx R11: %016lx R12: %016lx\n",
|
|
|
|
log_lvl, regs->r10, regs->r11, regs->r12);
|
|
|
|
printk("%sR13: %016lx R14: %016lx R15: %016lx\n",
|
|
|
|
log_lvl, regs->r13, regs->r14, regs->r15);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-31 19:41:51 +00:00
|
|
|
if (mode == SHOW_REGS_SHORT)
|
2017-12-04 14:07:09 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-31 19:41:51 +00:00
|
|
|
if (mode == SHOW_REGS_USER) {
|
|
|
|
rdmsrl(MSR_FS_BASE, fs);
|
|
|
|
rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
|
2020-06-29 14:48:46 +00:00
|
|
|
printk("%sFS: %016lx GS: %016lx\n",
|
|
|
|
log_lvl, fs, shadowgs);
|
2018-08-31 19:41:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-29 05:48:51 +00:00
|
|
|
asm("movl %%ds,%0" : "=r" (ds));
|
|
|
|
asm("movl %%es,%0" : "=r" (es));
|
2005-04-16 22:20:36 +00:00
|
|
|
asm("movl %%fs,%0" : "=r" (fsindex));
|
|
|
|
asm("movl %%gs,%0" : "=r" (gsindex));
|
|
|
|
|
|
|
|
rdmsrl(MSR_FS_BASE, fs);
|
2008-07-29 05:48:51 +00:00
|
|
|
rdmsrl(MSR_GS_BASE, gs);
|
|
|
|
rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-22 09:12:29 +00:00
|
|
|
cr0 = read_cr0();
|
|
|
|
cr2 = read_cr2();
|
2017-06-12 17:26:14 +00:00
|
|
|
cr3 = __read_cr3();
|
2014-10-24 22:58:08 +00:00
|
|
|
cr4 = __read_cr4();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-06-29 14:48:46 +00:00
|
|
|
printk("%sFS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
|
|
|
|
log_lvl, fs, fsindex, gs, gsindex, shadowgs);
|
|
|
|
printk("%sCS: %04lx DS: %04x ES: %04x CR0: %016lx\n",
|
|
|
|
log_lvl, regs->cs, ds, es, cr0);
|
|
|
|
printk("%sCR2: %016lx CR3: %016lx CR4: %016lx\n",
|
|
|
|
log_lvl, cr2, cr3, cr4);
|
2007-07-21 15:10:42 +00:00
|
|
|
|
|
|
|
get_debugreg(d0, 0);
|
|
|
|
get_debugreg(d1, 1);
|
|
|
|
get_debugreg(d2, 2);
|
|
|
|
get_debugreg(d3, 3);
|
|
|
|
get_debugreg(d6, 6);
|
|
|
|
get_debugreg(d7, 7);
|
2013-06-18 16:09:11 +00:00
|
|
|
|
|
|
|
/* Only print out debug registers if they are in their non-default state. */
|
2016-09-10 18:30:45 +00:00
|
|
|
if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
|
|
|
|
(d6 == DR6_RESERVED) && (d7 == 0x400))) {
|
2020-06-29 14:48:46 +00:00
|
|
|
printk("%sDR0: %016lx DR1: %016lx DR2: %016lx\n",
|
|
|
|
log_lvl, d0, d1, d2);
|
|
|
|
printk("%sDR3: %016lx DR6: %016lx DR7: %016lx\n",
|
|
|
|
log_lvl, d3, d6, d7);
|
2016-09-10 18:30:45 +00:00
|
|
|
}
|
2013-06-18 16:09:11 +00:00
|
|
|
|
2021-06-23 12:02:07 +00:00
|
|
|
if (cpu_feature_enabled(X86_FEATURE_OSPKE))
|
2020-06-29 14:48:46 +00:00
|
|
|
printk("%sPKRU: %08x\n", log_lvl, read_pkru());
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void release_thread(struct task_struct *dead_task)
|
|
|
|
{
|
2019-07-12 22:41:52 +00:00
|
|
|
WARN_ON(dead_task->mm);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 14:11:37 +00:00
|
|
|
enum which_selector {
|
|
|
|
FS,
|
|
|
|
GS
|
|
|
|
};
|
|
|
|
|
2020-05-28 20:13:50 +00:00
|
|
|
/*
|
|
|
|
* Out of line to be protected from kprobes and tracing. If this would be
|
|
|
|
* traced or probed than any access to a per CPU variable happens with
|
|
|
|
* the wrong GS.
|
|
|
|
*
|
|
|
|
* It is not used on Xen paravirt. When paravirt support is needed, it
|
|
|
|
* needs to be renamed with native_ prefix.
|
|
|
|
*/
|
|
|
|
static noinstr unsigned long __rdgsbase_inactive(void)
|
|
|
|
{
|
|
|
|
unsigned long gsbase;
|
|
|
|
|
|
|
|
lockdep_assert_irqs_disabled();
|
|
|
|
|
2022-11-04 07:27:01 +00:00
|
|
|
if (!cpu_feature_enabled(X86_FEATURE_XENPV)) {
|
2020-06-26 17:24:30 +00:00
|
|
|
native_swapgs();
|
|
|
|
gsbase = rdgsbase();
|
|
|
|
native_swapgs();
|
|
|
|
} else {
|
|
|
|
instrumentation_begin();
|
|
|
|
rdmsrl(MSR_KERNEL_GS_BASE, gsbase);
|
|
|
|
instrumentation_end();
|
|
|
|
}
|
2020-05-28 20:13:50 +00:00
|
|
|
|
|
|
|
return gsbase;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Out of line to be protected from kprobes and tracing. If this would be
|
|
|
|
* traced or probed than any access to a per CPU variable happens with
|
|
|
|
* the wrong GS.
|
|
|
|
*
|
|
|
|
* It is not used on Xen paravirt. When paravirt support is needed, it
|
|
|
|
* needs to be renamed with native_ prefix.
|
|
|
|
*/
|
|
|
|
static noinstr void __wrgsbase_inactive(unsigned long gsbase)
|
|
|
|
{
|
|
|
|
lockdep_assert_irqs_disabled();
|
|
|
|
|
2022-11-04 07:27:01 +00:00
|
|
|
if (!cpu_feature_enabled(X86_FEATURE_XENPV)) {
|
2020-06-26 17:24:30 +00:00
|
|
|
native_swapgs();
|
|
|
|
wrgsbase(gsbase);
|
|
|
|
native_swapgs();
|
|
|
|
} else {
|
|
|
|
instrumentation_begin();
|
|
|
|
wrmsrl(MSR_KERNEL_GS_BASE, gsbase);
|
|
|
|
instrumentation_end();
|
|
|
|
}
|
2020-05-28 20:13:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 14:11:37 +00:00
|
|
|
/*
|
|
|
|
* Saves the FS or GS base for an outgoing thread if FSGSBASE extensions are
|
|
|
|
* not available. The goal is to be reasonably fast on non-FSGSBASE systems.
|
|
|
|
* It's forcibly inlined because it'll generate better code and this function
|
|
|
|
* is hot.
|
|
|
|
*/
|
|
|
|
static __always_inline void save_base_legacy(struct task_struct *prev_p,
|
|
|
|
unsigned short selector,
|
|
|
|
enum which_selector which)
|
|
|
|
{
|
|
|
|
if (likely(selector == 0)) {
|
|
|
|
/*
|
|
|
|
* On Intel (without X86_BUG_NULL_SEG), the segment base could
|
|
|
|
* be the pre-existing saved base or it could be zero. On AMD
|
|
|
|
* (with X86_BUG_NULL_SEG), the segment base could be almost
|
|
|
|
* anything.
|
|
|
|
*
|
|
|
|
* This branch is very hot (it's hit twice on almost every
|
|
|
|
* context switch between 64-bit programs), and avoiding
|
|
|
|
* the RDMSR helps a lot, so we just assume that whatever
|
|
|
|
* value is already saved is correct. This matches historical
|
|
|
|
* Linux behavior, so it won't break existing applications.
|
|
|
|
*
|
|
|
|
* To avoid leaking state, on non-X86_BUG_NULL_SEG CPUs, if we
|
|
|
|
* report that the base is zero, it needs to actually be zero:
|
|
|
|
* see the corresponding logic in load_seg_legacy.
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the selector is 1, 2, or 3, then the base is zero on
|
|
|
|
* !X86_BUG_NULL_SEG CPUs and could be anything on
|
|
|
|
* X86_BUG_NULL_SEG CPUs. In the latter case, Linux
|
|
|
|
* has never attempted to preserve the base across context
|
|
|
|
* switches.
|
|
|
|
*
|
|
|
|
* If selector > 3, then it refers to a real segment, and
|
|
|
|
* saving the base isn't necessary.
|
|
|
|
*/
|
|
|
|
if (which == FS)
|
|
|
|
prev_p->thread.fsbase = 0;
|
|
|
|
else
|
|
|
|
prev_p->thread.gsbase = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void save_fsgs(struct task_struct *task)
|
|
|
|
{
|
|
|
|
savesegment(fs, task->thread.fsindex);
|
|
|
|
savesegment(gs, task->thread.gsindex);
|
2020-05-28 20:13:51 +00:00
|
|
|
if (static_cpu_has(X86_FEATURE_FSGSBASE)) {
|
|
|
|
/*
|
|
|
|
* If FSGSBASE is enabled, we can't make any useful guesses
|
|
|
|
* about the base, and user code expects us to save the current
|
|
|
|
* value. Fortunately, reading the base directly is efficient.
|
|
|
|
*/
|
|
|
|
task->thread.fsbase = rdfsbase();
|
|
|
|
task->thread.gsbase = __rdgsbase_inactive();
|
|
|
|
} else {
|
|
|
|
save_base_legacy(task, task->thread.fsindex, FS);
|
|
|
|
save_base_legacy(task, task->thread.gsindex, GS);
|
|
|
|
}
|
2017-08-01 14:11:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 17:48:04 +00:00
|
|
|
/*
|
|
|
|
* While a process is running,current->thread.fsbase and current->thread.gsbase
|
2020-05-28 20:13:52 +00:00
|
|
|
* may not match the corresponding CPU registers (see save_base_legacy()).
|
2018-03-13 17:48:04 +00:00
|
|
|
*/
|
2020-05-28 20:13:52 +00:00
|
|
|
void current_save_fsgs(void)
|
2018-03-13 17:48:04 +00:00
|
|
|
{
|
2020-05-28 20:13:52 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Interrupts need to be off for FSGSBASE */
|
|
|
|
local_irq_save(flags);
|
2018-03-13 17:48:04 +00:00
|
|
|
save_fsgs(current);
|
2020-05-28 20:13:52 +00:00
|
|
|
local_irq_restore(flags);
|
2018-03-13 17:48:04 +00:00
|
|
|
}
|
2020-05-28 20:13:52 +00:00
|
|
|
#if IS_ENABLED(CONFIG_KVM)
|
|
|
|
EXPORT_SYMBOL_GPL(current_save_fsgs);
|
2018-03-13 17:48:04 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-01 14:11:37 +00:00
|
|
|
static __always_inline void loadseg(enum which_selector which,
|
|
|
|
unsigned short sel)
|
|
|
|
{
|
|
|
|
if (which == FS)
|
|
|
|
loadsegment(fs, sel);
|
|
|
|
else
|
|
|
|
load_gs_index(sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline void load_seg_legacy(unsigned short prev_index,
|
|
|
|
unsigned long prev_base,
|
|
|
|
unsigned short next_index,
|
|
|
|
unsigned long next_base,
|
|
|
|
enum which_selector which)
|
|
|
|
{
|
|
|
|
if (likely(next_index <= 3)) {
|
|
|
|
/*
|
|
|
|
* The next task is using 64-bit TLS, is not using this
|
|
|
|
* segment at all, or is having fun with arcane CPU features.
|
|
|
|
*/
|
|
|
|
if (next_base == 0) {
|
|
|
|
/*
|
|
|
|
* Nasty case: on AMD CPUs, we need to forcibly zero
|
|
|
|
* the base.
|
|
|
|
*/
|
|
|
|
if (static_cpu_has_bug(X86_BUG_NULL_SEG)) {
|
|
|
|
loadseg(which, __USER_DS);
|
|
|
|
loadseg(which, next_index);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We could try to exhaustively detect cases
|
|
|
|
* under which we can skip the segment load,
|
|
|
|
* but there's really only one case that matters
|
|
|
|
* for performance: if both the previous and
|
|
|
|
* next states are fully zeroed, we can skip
|
|
|
|
* the load.
|
|
|
|
*
|
|
|
|
* (This assumes that prev_base == 0 has no
|
|
|
|
* false positives. This is the case on
|
|
|
|
* Intel-style CPUs.)
|
|
|
|
*/
|
|
|
|
if (likely(prev_index | next_index | prev_base))
|
|
|
|
loadseg(which, next_index);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (prev_index != next_index)
|
|
|
|
loadseg(which, next_index);
|
|
|
|
wrmsrl(which == FS ? MSR_FS_BASE : MSR_KERNEL_GS_BASE,
|
|
|
|
next_base);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The next task is using a real segment. Loading the selector
|
|
|
|
* is sufficient.
|
|
|
|
*/
|
|
|
|
loadseg(which, next_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 12:02:18 +00:00
|
|
|
/*
|
|
|
|
* Store prev's PKRU value and load next's PKRU value if they differ. PKRU
|
|
|
|
* is not XSTATE managed on context switch because that would require a
|
|
|
|
* lookup in the task's FPU xsave buffer and require to keep that updated
|
|
|
|
* in various places.
|
|
|
|
*/
|
|
|
|
static __always_inline void x86_pkru_load(struct thread_struct *prev,
|
|
|
|
struct thread_struct *next)
|
|
|
|
{
|
|
|
|
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Stash the prev task's value: */
|
|
|
|
prev->pkru = rdpkru();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PKRU writes are slightly expensive. Avoid them when not
|
|
|
|
* strictly necessary:
|
|
|
|
*/
|
|
|
|
if (prev->pkru != next->pkru)
|
|
|
|
wrpkru(next->pkru);
|
|
|
|
}
|
|
|
|
|
2018-09-18 23:08:56 +00:00
|
|
|
static __always_inline void x86_fsgsbase_load(struct thread_struct *prev,
|
|
|
|
struct thread_struct *next)
|
|
|
|
{
|
2020-05-28 20:13:51 +00:00
|
|
|
if (static_cpu_has(X86_FEATURE_FSGSBASE)) {
|
|
|
|
/* Update the FS and GS selectors if they could have changed. */
|
|
|
|
if (unlikely(prev->fsindex || next->fsindex))
|
|
|
|
loadseg(FS, next->fsindex);
|
|
|
|
if (unlikely(prev->gsindex || next->gsindex))
|
|
|
|
loadseg(GS, next->gsindex);
|
|
|
|
|
|
|
|
/* Update the bases. */
|
|
|
|
wrfsbase(next->fsbase);
|
|
|
|
__wrgsbase_inactive(next->gsbase);
|
|
|
|
} else {
|
|
|
|
load_seg_legacy(prev->fsindex, prev->fsbase,
|
|
|
|
next->fsindex, next->fsbase, FS);
|
|
|
|
load_seg_legacy(prev->gsindex, prev->gsbase,
|
|
|
|
next->gsindex, next->gsbase, GS);
|
|
|
|
}
|
2018-09-18 23:08:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:24:29 +00:00
|
|
|
unsigned long x86_fsgsbase_read_task(struct task_struct *task,
|
|
|
|
unsigned short selector)
|
2018-09-18 23:08:53 +00:00
|
|
|
{
|
|
|
|
unsigned short idx = selector >> 3;
|
|
|
|
unsigned long base;
|
|
|
|
|
|
|
|
if (likely((selector & SEGMENT_TI_MASK) == 0)) {
|
|
|
|
if (unlikely(idx >= GDT_ENTRIES))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are no user segments in the GDT with nonzero bases
|
|
|
|
* other than the TLS segments.
|
|
|
|
*/
|
|
|
|
if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
idx -= GDT_ENTRY_TLS_MIN;
|
|
|
|
base = get_desc_base(&task->thread.tls_array[idx]);
|
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_MODIFY_LDT_SYSCALL
|
|
|
|
struct ldt_struct *ldt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If performance here mattered, we could protect the LDT
|
|
|
|
* with RCU. This is a slow path, though, so we can just
|
|
|
|
* take the mutex.
|
|
|
|
*/
|
|
|
|
mutex_lock(&task->mm->context.lock);
|
|
|
|
ldt = task->mm->context.ldt;
|
2020-08-14 18:16:17 +00:00
|
|
|
if (unlikely(!ldt || idx >= ldt->nr_entries))
|
2018-09-18 23:08:53 +00:00
|
|
|
base = 0;
|
|
|
|
else
|
|
|
|
base = get_desc_base(ldt->entries + idx);
|
|
|
|
mutex_unlock(&task->mm->context.lock);
|
|
|
|
#else
|
|
|
|
base = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2020-05-28 20:13:50 +00:00
|
|
|
unsigned long x86_gsbase_read_cpu_inactive(void)
|
|
|
|
{
|
|
|
|
unsigned long gsbase;
|
|
|
|
|
2020-08-18 10:28:31 +00:00
|
|
|
if (boot_cpu_has(X86_FEATURE_FSGSBASE)) {
|
2020-05-28 20:13:50 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
gsbase = __rdgsbase_inactive();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
} else {
|
|
|
|
rdmsrl(MSR_KERNEL_GS_BASE, gsbase);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gsbase;
|
|
|
|
}
|
|
|
|
|
|
|
|
void x86_gsbase_write_cpu_inactive(unsigned long gsbase)
|
|
|
|
{
|
2020-08-18 10:28:31 +00:00
|
|
|
if (boot_cpu_has(X86_FEATURE_FSGSBASE)) {
|
2020-05-28 20:13:50 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
__wrgsbase_inactive(gsbase);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
} else {
|
|
|
|
wrmsrl(MSR_KERNEL_GS_BASE, gsbase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 23:08:53 +00:00
|
|
|
unsigned long x86_fsbase_read_task(struct task_struct *task)
|
|
|
|
{
|
|
|
|
unsigned long fsbase;
|
|
|
|
|
|
|
|
if (task == current)
|
|
|
|
fsbase = x86_fsbase_read_cpu();
|
2020-08-18 10:28:31 +00:00
|
|
|
else if (boot_cpu_has(X86_FEATURE_FSGSBASE) ||
|
2020-05-28 20:13:53 +00:00
|
|
|
(task->thread.fsindex == 0))
|
2018-09-18 23:08:53 +00:00
|
|
|
fsbase = task->thread.fsbase;
|
|
|
|
else
|
|
|
|
fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex);
|
|
|
|
|
|
|
|
return fsbase;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long x86_gsbase_read_task(struct task_struct *task)
|
|
|
|
{
|
|
|
|
unsigned long gsbase;
|
|
|
|
|
|
|
|
if (task == current)
|
|
|
|
gsbase = x86_gsbase_read_cpu_inactive();
|
2020-08-18 10:28:31 +00:00
|
|
|
else if (boot_cpu_has(X86_FEATURE_FSGSBASE) ||
|
2020-05-28 20:13:53 +00:00
|
|
|
(task->thread.gsindex == 0))
|
2018-09-18 23:08:53 +00:00
|
|
|
gsbase = task->thread.gsbase;
|
|
|
|
else
|
|
|
|
gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex);
|
|
|
|
|
|
|
|
return gsbase;
|
|
|
|
}
|
|
|
|
|
2018-11-26 19:55:24 +00:00
|
|
|
void x86_fsbase_write_task(struct task_struct *task, unsigned long fsbase)
|
2018-09-18 23:08:53 +00:00
|
|
|
{
|
2018-11-26 19:55:24 +00:00
|
|
|
WARN_ON_ONCE(task == current);
|
2018-09-18 23:08:53 +00:00
|
|
|
|
|
|
|
task->thread.fsbase = fsbase;
|
|
|
|
}
|
|
|
|
|
2018-11-26 19:55:24 +00:00
|
|
|
void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase)
|
2018-09-18 23:08:53 +00:00
|
|
|
{
|
2018-11-26 19:55:24 +00:00
|
|
|
WARN_ON_ONCE(task == current);
|
2018-09-18 23:08:53 +00:00
|
|
|
|
|
|
|
task->thread.gsbase = gsbase;
|
|
|
|
}
|
|
|
|
|
2009-10-09 22:56:53 +00:00
|
|
|
static void
|
|
|
|
start_thread_common(struct pt_regs *regs, unsigned long new_ip,
|
|
|
|
unsigned long new_sp,
|
|
|
|
unsigned int _cs, unsigned int _ss, unsigned int _ds)
|
2008-02-21 04:18:40 +00:00
|
|
|
{
|
2017-08-01 14:11:34 +00:00
|
|
|
WARN_ON_ONCE(regs != current_pt_regs());
|
|
|
|
|
|
|
|
if (static_cpu_has(X86_BUG_NULL_SEG)) {
|
|
|
|
/* Loading zero below won't clear the base. */
|
|
|
|
loadsegment(fs, __USER_DS);
|
|
|
|
load_gs_index(__USER_DS);
|
|
|
|
}
|
|
|
|
|
2023-06-13 00:10:52 +00:00
|
|
|
reset_thread_features();
|
|
|
|
|
2008-06-25 04:19:00 +00:00
|
|
|
loadsegment(fs, 0);
|
2009-10-09 22:56:53 +00:00
|
|
|
loadsegment(es, _ds);
|
|
|
|
loadsegment(ds, _ds);
|
2008-02-21 04:18:40 +00:00
|
|
|
load_gs_index(0);
|
2017-08-01 14:11:34 +00:00
|
|
|
|
2008-02-21 04:18:40 +00:00
|
|
|
regs->ip = new_ip;
|
|
|
|
regs->sp = new_sp;
|
2009-10-09 22:56:53 +00:00
|
|
|
regs->cs = _cs;
|
|
|
|
regs->ss = _ss;
|
2009-10-09 01:02:54 +00:00
|
|
|
regs->flags = X86_EFLAGS_IF;
|
2008-02-21 04:18:40 +00:00
|
|
|
}
|
2009-10-09 22:56:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
|
|
|
|
{
|
|
|
|
start_thread_common(regs, new_ip, new_sp,
|
|
|
|
__USER_CS, __USER_DS, 0);
|
|
|
|
}
|
2018-08-19 23:08:53 +00:00
|
|
|
EXPORT_SYMBOL_GPL(start_thread);
|
2008-02-21 04:18:40 +00:00
|
|
|
|
2015-06-22 11:55:13 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
2020-10-04 03:25:32 +00:00
|
|
|
void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp, bool x32)
|
2009-10-09 01:02:54 +00:00
|
|
|
{
|
2009-10-09 22:56:53 +00:00
|
|
|
start_thread_common(regs, new_ip, new_sp,
|
2020-10-04 03:25:32 +00:00
|
|
|
x32 ? __USER_CS : __USER32_CS,
|
2012-02-19 18:06:34 +00:00
|
|
|
__USER_DS, __USER_DS);
|
2009-10-09 01:02:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-02-21 04:18:40 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* switch_to(x,y) should switch tasks from x to y.
|
|
|
|
*
|
2008-01-30 12:31:03 +00:00
|
|
|
* This could still be optimized:
|
2005-04-16 22:20:36 +00:00
|
|
|
* - fold all the options into a flag word and test it with a single test.
|
|
|
|
* - could test fs/gs bitsliced
|
2006-02-03 20:51:38 +00:00
|
|
|
*
|
|
|
|
* Kprobes not supported here. Set the probe on schedule instead.
|
2008-12-06 02:40:00 +00:00
|
|
|
* Function graph tracer not supported too.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2022-09-15 15:04:07 +00:00
|
|
|
__no_kmsan_checks
|
2013-08-05 22:02:39 +00:00
|
|
|
__visible __notrace_funcgraph struct task_struct *
|
2005-11-05 16:25:54 +00:00
|
|
|
__switch_to(struct task_struct *prev_p, struct task_struct *next_p)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-08 22:06:26 +00:00
|
|
|
struct thread_struct *prev = &prev_p->thread;
|
|
|
|
struct thread_struct *next = &next_p->thread;
|
2015-04-23 15:43:27 +00:00
|
|
|
struct fpu *prev_fpu = &prev->fpu;
|
2008-01-30 12:31:03 +00:00
|
|
|
int cpu = smp_processor_id();
|
2006-09-26 08:52:36 +00:00
|
|
|
|
2017-07-11 15:33:38 +00:00
|
|
|
WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ENTRY) &&
|
2022-09-15 11:11:05 +00:00
|
|
|
this_cpu_read(pcpu_hot.hardirq_stack_inuse));
|
2017-07-11 15:33:38 +00:00
|
|
|
|
2019-04-03 16:41:52 +00:00
|
|
|
if (!test_thread_flag(TIF_NEED_FPU_LOAD))
|
|
|
|
switch_fpu_prepare(prev_fpu, cpu);
|
2012-02-17 03:11:15 +00:00
|
|
|
|
2008-06-25 04:19:24 +00:00
|
|
|
/* We must save %fs and %gs before load_TLS() because
|
|
|
|
* %fs and %gs may be cleared by load_TLS().
|
|
|
|
*
|
|
|
|
* (e.g. xen_load_tls())
|
|
|
|
*/
|
2017-08-01 14:11:37 +00:00
|
|
|
save_fsgs(prev_p);
|
2008-06-25 04:19:24 +00:00
|
|
|
|
x86_64, switch_to(): Load TLS descriptors before switching DS and ES
Otherwise, if buggy user code points DS or ES into the TLS
array, they would be corrupted after a context switch.
This also significantly improves the comments and documents some
gotchas in the code.
Before this patch, the both tests below failed. With this
patch, the es test passes, although the gsbase test still fails.
----- begin es test -----
/*
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned short GDT3(int idx)
{
return (idx << 3) | 3;
}
static int create_tls(int idx, unsigned int base)
{
struct user_desc desc = {
.entry_number = idx,
.base_addr = base,
.limit = 0xfffff,
.seg_32bit = 1,
.contents = 0, /* Data, grow-up */
.read_exec_only = 0,
.limit_in_pages = 1,
.seg_not_present = 0,
.useable = 0,
};
if (syscall(SYS_set_thread_area, &desc) != 0)
err(1, "set_thread_area");
return desc.entry_number;
}
int main()
{
int idx = create_tls(-1, 0);
printf("Allocated GDT index %d\n", idx);
unsigned short orig_es;
asm volatile ("mov %%es,%0" : "=rm" (orig_es));
int errors = 0;
int total = 1000;
for (int i = 0; i < total; i++) {
asm volatile ("mov %0,%%es" : : "rm" (GDT3(idx)));
usleep(100);
unsigned short es;
asm volatile ("mov %%es,%0" : "=rm" (es));
asm volatile ("mov %0,%%es" : : "rm" (orig_es));
if (es != GDT3(idx)) {
if (errors == 0)
printf("[FAIL]\tES changed from 0x%hx to 0x%hx\n",
GDT3(idx), es);
errors++;
}
}
if (errors) {
printf("[FAIL]\tES was corrupted %d/%d times\n", errors, total);
return 1;
} else {
printf("[OK]\tES was preserved\n");
return 0;
}
}
----- end es test -----
----- begin gsbase test -----
/*
* gsbase.c, a gsbase test
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned char *testptr, *testptr2;
static unsigned char read_gs_testvals(void)
{
unsigned char ret;
asm volatile ("movb %%gs:%1, %0" : "=r" (ret) : "m" (*testptr));
return ret;
}
int main()
{
int errors = 0;
testptr = mmap((void *)0x200000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr == MAP_FAILED)
err(1, "mmap");
testptr2 = mmap((void *)0x300000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr2 == MAP_FAILED)
err(1, "mmap");
*testptr = 0;
*testptr2 = 1;
if (syscall(SYS_arch_prctl, ARCH_SET_GS,
(unsigned long)testptr2 - (unsigned long)testptr) != 0)
err(1, "ARCH_SET_GS");
usleep(100);
if (read_gs_testvals() == 1) {
printf("[OK]\tARCH_SET_GS worked\n");
} else {
printf("[FAIL]\tARCH_SET_GS failed\n");
errors++;
}
asm volatile ("mov %0,%%gs" : : "r" (0));
if (read_gs_testvals() == 0) {
printf("[OK]\tWriting 0 to gs worked\n");
} else {
printf("[FAIL]\tWriting 0 to gs failed\n");
errors++;
}
usleep(100);
if (read_gs_testvals() == 0) {
printf("[OK]\tgsbase is still zero\n");
} else {
printf("[FAIL]\tgsbase was corrupted\n");
errors++;
}
return errors == 0 ? 0 : 1;
}
----- end gsbase test -----
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: <stable@vger.kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/509d27c9fec78217691c3dad91cec87e1006b34a.1418075657.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-12-08 21:55:20 +00:00
|
|
|
/*
|
|
|
|
* Load TLS before restoring any segments so that segment loads
|
|
|
|
* reference the correct GDT entries.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
load_TLS(next, cpu);
|
|
|
|
|
2008-06-25 04:19:23 +00:00
|
|
|
/*
|
x86_64, switch_to(): Load TLS descriptors before switching DS and ES
Otherwise, if buggy user code points DS or ES into the TLS
array, they would be corrupted after a context switch.
This also significantly improves the comments and documents some
gotchas in the code.
Before this patch, the both tests below failed. With this
patch, the es test passes, although the gsbase test still fails.
----- begin es test -----
/*
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned short GDT3(int idx)
{
return (idx << 3) | 3;
}
static int create_tls(int idx, unsigned int base)
{
struct user_desc desc = {
.entry_number = idx,
.base_addr = base,
.limit = 0xfffff,
.seg_32bit = 1,
.contents = 0, /* Data, grow-up */
.read_exec_only = 0,
.limit_in_pages = 1,
.seg_not_present = 0,
.useable = 0,
};
if (syscall(SYS_set_thread_area, &desc) != 0)
err(1, "set_thread_area");
return desc.entry_number;
}
int main()
{
int idx = create_tls(-1, 0);
printf("Allocated GDT index %d\n", idx);
unsigned short orig_es;
asm volatile ("mov %%es,%0" : "=rm" (orig_es));
int errors = 0;
int total = 1000;
for (int i = 0; i < total; i++) {
asm volatile ("mov %0,%%es" : : "rm" (GDT3(idx)));
usleep(100);
unsigned short es;
asm volatile ("mov %%es,%0" : "=rm" (es));
asm volatile ("mov %0,%%es" : : "rm" (orig_es));
if (es != GDT3(idx)) {
if (errors == 0)
printf("[FAIL]\tES changed from 0x%hx to 0x%hx\n",
GDT3(idx), es);
errors++;
}
}
if (errors) {
printf("[FAIL]\tES was corrupted %d/%d times\n", errors, total);
return 1;
} else {
printf("[OK]\tES was preserved\n");
return 0;
}
}
----- end es test -----
----- begin gsbase test -----
/*
* gsbase.c, a gsbase test
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned char *testptr, *testptr2;
static unsigned char read_gs_testvals(void)
{
unsigned char ret;
asm volatile ("movb %%gs:%1, %0" : "=r" (ret) : "m" (*testptr));
return ret;
}
int main()
{
int errors = 0;
testptr = mmap((void *)0x200000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr == MAP_FAILED)
err(1, "mmap");
testptr2 = mmap((void *)0x300000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr2 == MAP_FAILED)
err(1, "mmap");
*testptr = 0;
*testptr2 = 1;
if (syscall(SYS_arch_prctl, ARCH_SET_GS,
(unsigned long)testptr2 - (unsigned long)testptr) != 0)
err(1, "ARCH_SET_GS");
usleep(100);
if (read_gs_testvals() == 1) {
printf("[OK]\tARCH_SET_GS worked\n");
} else {
printf("[FAIL]\tARCH_SET_GS failed\n");
errors++;
}
asm volatile ("mov %0,%%gs" : : "r" (0));
if (read_gs_testvals() == 0) {
printf("[OK]\tWriting 0 to gs worked\n");
} else {
printf("[FAIL]\tWriting 0 to gs failed\n");
errors++;
}
usleep(100);
if (read_gs_testvals() == 0) {
printf("[OK]\tgsbase is still zero\n");
} else {
printf("[FAIL]\tgsbase was corrupted\n");
errors++;
}
return errors == 0 ? 0 : 1;
}
----- end gsbase test -----
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: <stable@vger.kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/509d27c9fec78217691c3dad91cec87e1006b34a.1418075657.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-12-08 21:55:20 +00:00
|
|
|
* Leave lazy mode, flushing any hypercalls made here. This
|
|
|
|
* must be done after loading TLS entries in the GDT but before
|
2019-04-03 16:41:31 +00:00
|
|
|
* loading segments that might reference them.
|
2008-06-25 04:19:23 +00:00
|
|
|
*/
|
2009-02-18 19:18:57 +00:00
|
|
|
arch_end_context_switch(next_p);
|
2008-06-25 04:19:23 +00:00
|
|
|
|
x86_64, switch_to(): Load TLS descriptors before switching DS and ES
Otherwise, if buggy user code points DS or ES into the TLS
array, they would be corrupted after a context switch.
This also significantly improves the comments and documents some
gotchas in the code.
Before this patch, the both tests below failed. With this
patch, the es test passes, although the gsbase test still fails.
----- begin es test -----
/*
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned short GDT3(int idx)
{
return (idx << 3) | 3;
}
static int create_tls(int idx, unsigned int base)
{
struct user_desc desc = {
.entry_number = idx,
.base_addr = base,
.limit = 0xfffff,
.seg_32bit = 1,
.contents = 0, /* Data, grow-up */
.read_exec_only = 0,
.limit_in_pages = 1,
.seg_not_present = 0,
.useable = 0,
};
if (syscall(SYS_set_thread_area, &desc) != 0)
err(1, "set_thread_area");
return desc.entry_number;
}
int main()
{
int idx = create_tls(-1, 0);
printf("Allocated GDT index %d\n", idx);
unsigned short orig_es;
asm volatile ("mov %%es,%0" : "=rm" (orig_es));
int errors = 0;
int total = 1000;
for (int i = 0; i < total; i++) {
asm volatile ("mov %0,%%es" : : "rm" (GDT3(idx)));
usleep(100);
unsigned short es;
asm volatile ("mov %%es,%0" : "=rm" (es));
asm volatile ("mov %0,%%es" : : "rm" (orig_es));
if (es != GDT3(idx)) {
if (errors == 0)
printf("[FAIL]\tES changed from 0x%hx to 0x%hx\n",
GDT3(idx), es);
errors++;
}
}
if (errors) {
printf("[FAIL]\tES was corrupted %d/%d times\n", errors, total);
return 1;
} else {
printf("[OK]\tES was preserved\n");
return 0;
}
}
----- end es test -----
----- begin gsbase test -----
/*
* gsbase.c, a gsbase test
* Copyright (c) 2014 Andy Lutomirski
* GPL v2
*/
static unsigned char *testptr, *testptr2;
static unsigned char read_gs_testvals(void)
{
unsigned char ret;
asm volatile ("movb %%gs:%1, %0" : "=r" (ret) : "m" (*testptr));
return ret;
}
int main()
{
int errors = 0;
testptr = mmap((void *)0x200000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr == MAP_FAILED)
err(1, "mmap");
testptr2 = mmap((void *)0x300000000UL, 1, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
if (testptr2 == MAP_FAILED)
err(1, "mmap");
*testptr = 0;
*testptr2 = 1;
if (syscall(SYS_arch_prctl, ARCH_SET_GS,
(unsigned long)testptr2 - (unsigned long)testptr) != 0)
err(1, "ARCH_SET_GS");
usleep(100);
if (read_gs_testvals() == 1) {
printf("[OK]\tARCH_SET_GS worked\n");
} else {
printf("[FAIL]\tARCH_SET_GS failed\n");
errors++;
}
asm volatile ("mov %0,%%gs" : : "r" (0));
if (read_gs_testvals() == 0) {
printf("[OK]\tWriting 0 to gs worked\n");
} else {
printf("[FAIL]\tWriting 0 to gs failed\n");
errors++;
}
usleep(100);
if (read_gs_testvals() == 0) {
printf("[OK]\tgsbase is still zero\n");
} else {
printf("[FAIL]\tgsbase was corrupted\n");
errors++;
}
return errors == 0 ? 0 : 1;
}
----- end gsbase test -----
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: <stable@vger.kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/509d27c9fec78217691c3dad91cec87e1006b34a.1418075657.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-12-08 21:55:20 +00:00
|
|
|
/* Switch DS and ES.
|
|
|
|
*
|
|
|
|
* Reading them only returns the selectors, but writing them (if
|
|
|
|
* nonzero) loads the full descriptor from the GDT or LDT. The
|
|
|
|
* LDT for next is loaded in switch_mm, and the GDT is loaded
|
|
|
|
* above.
|
|
|
|
*
|
|
|
|
* We therefore need to write new values to the segment
|
|
|
|
* registers on every context switch unless both the new and old
|
|
|
|
* values are zero.
|
|
|
|
*
|
|
|
|
* Note that we don't need to do anything for CS and SS, as
|
|
|
|
* those are saved and restored as part of pt_regs.
|
|
|
|
*/
|
|
|
|
savesegment(es, prev->es);
|
|
|
|
if (unlikely(next->es | prev->es))
|
|
|
|
loadsegment(es, next->es);
|
|
|
|
|
|
|
|
savesegment(ds, prev->ds);
|
|
|
|
if (unlikely(next->ds | prev->ds))
|
|
|
|
loadsegment(ds, next->ds);
|
|
|
|
|
2018-09-18 23:08:56 +00:00
|
|
|
x86_fsgsbase_load(prev, next);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-23 12:02:18 +00:00
|
|
|
x86_pkru_load(prev, next);
|
|
|
|
|
2008-07-29 05:48:51 +00:00
|
|
|
/*
|
2006-03-25 15:29:25 +00:00
|
|
|
* Switch the PDA and FPU contexts.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2022-09-15 11:11:01 +00:00
|
|
|
raw_cpu_write(pcpu_hot.current_task, next_p);
|
2022-09-15 11:11:04 +00:00
|
|
|
raw_cpu_write(pcpu_hot.top_of_stack, task_top_of_stack(next_p));
|
2006-04-20 00:36:45 +00:00
|
|
|
|
2021-10-15 01:15:54 +00:00
|
|
|
switch_fpu_finish();
|
2019-04-03 16:41:36 +00:00
|
|
|
|
2017-11-02 07:59:09 +00:00
|
|
|
/* Reload sp0. */
|
2018-07-18 09:40:51 +00:00
|
|
|
update_task_stack(next_p);
|
2015-03-07 01:50:18 +00:00
|
|
|
|
2018-11-25 18:33:47 +00:00
|
|
|
switch_to_extra(prev_p, next_p);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-04-26 23:47:59 +00:00
|
|
|
if (static_cpu_has_bug(X86_BUG_SYSRET_SS_ATTRS)) {
|
|
|
|
/*
|
|
|
|
* AMD CPUs have a misfeature: SYSRET sets the SS selector but
|
|
|
|
* does not update the cached descriptor. As a result, if we
|
|
|
|
* do SYSRET while SS is NULL, we'll end up in user mode with
|
|
|
|
* SS apparently equal to __USER_DS but actually unusable.
|
|
|
|
*
|
|
|
|
* The straightforward workaround would be to fix it up just
|
|
|
|
* before SYSRET, but that would slow down the system call
|
|
|
|
* fast paths. Instead, we ensure that SS is never NULL in
|
|
|
|
* system call context. We do this by replacing NULL SS
|
|
|
|
* selectors at every context switch. SYSCALL sets up a valid
|
|
|
|
* SS, so the only way to get NULL is to re-enter the kernel
|
|
|
|
* from CPL 3 through an interrupt. Since that can't happen
|
|
|
|
* in the same task as a running syscall, we are guaranteed to
|
|
|
|
* context switch between every interrupt vector entry and a
|
|
|
|
* subsequent SYSRET.
|
|
|
|
*
|
|
|
|
* We read SS first because SS reads are much faster than
|
|
|
|
* writes. Out of caution, we force SS to __KERNEL_DS even if
|
|
|
|
* it previously had a different non-NULL value.
|
|
|
|
*/
|
|
|
|
unsigned short ss_sel;
|
|
|
|
savesegment(ss, ss_sel);
|
|
|
|
if (ss_sel != __KERNEL_DS)
|
|
|
|
loadsegment(ss, __KERNEL_DS);
|
|
|
|
}
|
|
|
|
|
2016-10-28 22:04:48 +00:00
|
|
|
/* Load the Intel cache allocation PQR MSR. */
|
x86/resctl: fix scheduler confusion with 'current'
The implementation of 'current' on x86 is very intentionally special: it
is a very common thing to look up, and it uses 'this_cpu_read_stable()'
to get the current thread pointer efficiently from per-cpu storage.
And the keyword in there is 'stable': the current thread pointer never
changes as far as a single thread is concerned. Even if when a thread
is preempted, or moved to another CPU, or even across an explicit call
'schedule()' that thread will still have the same value for 'current'.
It is, after all, the kernel base pointer to thread-local storage.
That's why it's stable to begin with, but it's also why it's important
enough that we have that special 'this_cpu_read_stable()' access for it.
So this is all done very intentionally to allow the compiler to treat
'current' as a value that never visibly changes, so that the compiler
can do CSE and combine multiple different 'current' accesses into one.
However, there is obviously one very special situation when the
currently running thread does actually change: inside the scheduler
itself.
So the scheduler code paths are special, and do not have a 'current'
thread at all. Instead there are _two_ threads: the previous and the
next thread - typically called 'prev' and 'next' (or prev_p/next_p)
internally.
So this is all actually quite straightforward and simple, and not all
that complicated.
Except for when you then have special code that is run in scheduler
context, that code then has to be aware that 'current' isn't really a
valid thing. Did you mean 'prev'? Did you mean 'next'?
In fact, even if then look at the code, and you use 'current' after the
new value has been assigned to the percpu variable, we have explicitly
told the compiler that 'current' is magical and always stable. So the
compiler is quite free to use an older (or newer) value of 'current',
and the actual assignment to the percpu storage is not relevant even if
it might look that way.
Which is exactly what happened in the resctl code, that blithely used
'current' in '__resctrl_sched_in()' when it really wanted the new
process state (as implied by the name: we're scheduling 'into' that new
resctl state). And clang would end up just using the old thread pointer
value at least in some configurations.
This could have happened with gcc too, and purely depends on random
compiler details. Clang just seems to have been more aggressive about
moving the read of the per-cpu current_task pointer around.
The fix is trivial: just make the resctl code adhere to the scheduler
rules of using the prev/next thread pointer explicitly, instead of using
'current' in a situation where it just wasn't valid.
That same code is then also used outside of the scheduler context (when
a thread resctl state is explicitly changed), and then we will just pass
in 'current' as that pointer, of course. There is no ambiguity in that
case.
The fix may be trivial, but noticing and figuring out what went wrong
was not. The credit for that goes to Stephane Eranian.
Reported-by: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/20230303231133.1486085-1-eranian@google.com/
Link: https://lore.kernel.org/lkml/alpine.LFD.2.01.0908011214330.3304@localhost.localdomain/
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Tested-by: Stephane Eranian <eranian@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-03-07 21:06:29 +00:00
|
|
|
resctrl_sched_in(next_p);
|
2016-10-28 22:04:48 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return prev_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_personality_64bit(void)
|
|
|
|
{
|
|
|
|
/* inherit personality from parent */
|
|
|
|
|
|
|
|
/* Make sure to be in 64bit mode */
|
2012-02-06 21:03:09 +00:00
|
|
|
clear_thread_flag(TIF_ADDR32);
|
2017-03-31 11:11:37 +00:00
|
|
|
/* Pretend that this comes from a 64bit execve */
|
|
|
|
task_pt_regs(current)->orig_ax = __NR_execve;
|
2018-05-17 23:35:10 +00:00
|
|
|
current_thread_info()->status &= ~TS_COMPAT;
|
2011-03-13 19:49:14 +00:00
|
|
|
if (current->mm)
|
2023-03-12 11:25:57 +00:00
|
|
|
__set_bit(MM_CONTEXT_HAS_VSYSCALL, ¤t->mm->context.flags);
|
2011-03-13 19:49:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* TBD: overwrites user setup. Should have two bits.
|
|
|
|
But 64bit processes have always behaved this way,
|
|
|
|
so it's not too bad. The main problem is just that
|
2018-12-03 09:47:34 +00:00
|
|
|
32bit children are affected again. */
|
2005-04-16 22:20:36 +00:00
|
|
|
current->personality &= ~READ_IMPLIES_EXEC;
|
|
|
|
}
|
|
|
|
|
2017-03-31 11:11:37 +00:00
|
|
|
static void __set_personality_x32(void)
|
2010-01-29 06:14:43 +00:00
|
|
|
{
|
2022-03-14 19:48:41 +00:00
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
2017-03-31 11:11:37 +00:00
|
|
|
if (current->mm)
|
2020-10-04 03:25:35 +00:00
|
|
|
current->mm->context.flags = 0;
|
|
|
|
|
2017-03-31 11:11:37 +00:00
|
|
|
current->personality &= ~READ_IMPLIES_EXEC;
|
|
|
|
/*
|
2018-10-12 13:42:52 +00:00
|
|
|
* in_32bit_syscall() uses the presence of the x32 syscall bit
|
2017-03-31 11:11:37 +00:00
|
|
|
* flag to determine compat status. The x86 mmap() code relies on
|
|
|
|
* the syscall bitness so set x32 syscall bit right here to make
|
2018-10-12 13:42:52 +00:00
|
|
|
* in_32bit_syscall() work during exec().
|
2017-03-31 11:11:37 +00:00
|
|
|
*
|
|
|
|
* Pretend to come from a x32 execve.
|
|
|
|
*/
|
|
|
|
task_pt_regs(current)->orig_ax = __NR_x32_execve | __X32_SYSCALL_BIT;
|
2018-01-28 18:38:50 +00:00
|
|
|
current_thread_info()->status &= ~TS_COMPAT;
|
2017-03-31 11:11:37 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-01-29 06:14:43 +00:00
|
|
|
|
2017-03-31 11:11:37 +00:00
|
|
|
static void __set_personality_ia32(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
2020-10-04 03:25:35 +00:00
|
|
|
if (current->mm) {
|
|
|
|
/*
|
|
|
|
* uprobes applied to this MM need to know this and
|
|
|
|
* cannot use user_64bit_mode() at that time.
|
|
|
|
*/
|
2023-03-12 11:25:57 +00:00
|
|
|
__set_bit(MM_CONTEXT_UPROBE_IA32, ¤t->mm->context.flags);
|
2020-10-04 03:25:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:11:37 +00:00
|
|
|
current->personality |= force_personality32;
|
|
|
|
/* Prepare the first "return" to user space */
|
|
|
|
task_pt_regs(current)->orig_ax = __NR_ia32_execve;
|
2018-01-28 18:38:50 +00:00
|
|
|
current_thread_info()->status |= TS_COMPAT;
|
2017-03-31 11:11:37 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_personality_ia32(bool x32)
|
|
|
|
{
|
2010-01-29 06:14:43 +00:00
|
|
|
/* Make sure to be in 32bit mode */
|
2012-02-06 21:03:09 +00:00
|
|
|
set_thread_flag(TIF_ADDR32);
|
2010-01-29 06:14:43 +00:00
|
|
|
|
2017-03-31 11:11:37 +00:00
|
|
|
if (x32)
|
|
|
|
__set_personality_x32();
|
|
|
|
else
|
|
|
|
__set_personality_ia32();
|
2010-01-29 06:14:43 +00:00
|
|
|
}
|
2012-05-07 00:40:03 +00:00
|
|
|
EXPORT_SYMBOL_GPL(set_personality_ia32);
|
2010-01-29 06:14:43 +00:00
|
|
|
|
2016-09-15 06:42:51 +00:00
|
|
|
#ifdef CONFIG_CHECKPOINT_RESTORE
|
2016-09-05 13:33:05 +00:00
|
|
|
static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = map_vdso_once(image, addr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return (long)image->size;
|
|
|
|
}
|
2016-09-15 06:42:51 +00:00
|
|
|
#endif
|
2016-09-05 13:33:05 +00:00
|
|
|
|
2023-03-12 11:26:03 +00:00
|
|
|
#ifdef CONFIG_ADDRESS_MASKING
|
|
|
|
|
|
|
|
#define LAM_U57_BITS 6
|
|
|
|
|
|
|
|
static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits)
|
|
|
|
{
|
|
|
|
if (!cpu_feature_enabled(X86_FEATURE_LAM))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* PTRACE_ARCH_PRCTL */
|
|
|
|
if (current->mm != mm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2023-03-12 11:26:06 +00:00
|
|
|
if (mm_valid_pasid(mm) &&
|
|
|
|
!test_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &mm->context.flags))
|
2023-04-03 11:10:19 +00:00
|
|
|
return -EINVAL;
|
2023-03-12 11:26:06 +00:00
|
|
|
|
2023-03-12 11:26:03 +00:00
|
|
|
if (mmap_write_lock_killable(mm))
|
|
|
|
return -EINTR;
|
|
|
|
|
|
|
|
if (test_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags)) {
|
|
|
|
mmap_write_unlock(mm);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nr_bits) {
|
|
|
|
mmap_write_unlock(mm);
|
|
|
|
return -EINVAL;
|
|
|
|
} else if (nr_bits <= LAM_U57_BITS) {
|
|
|
|
mm->context.lam_cr3_mask = X86_CR3_LAM_U57;
|
|
|
|
mm->context.untag_mask = ~GENMASK(62, 57);
|
|
|
|
} else {
|
|
|
|
mmap_write_unlock(mm);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_cr3(__read_cr3() | mm->context.lam_cr3_mask);
|
|
|
|
set_tlbstate_lam_mode(mm);
|
|
|
|
set_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags);
|
|
|
|
|
|
|
|
mmap_write_unlock(mm);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-20 08:16:22 +00:00
|
|
|
long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
|
2008-07-29 05:48:51 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-03-20 08:16:20 +00:00
|
|
|
switch (option) {
|
2018-09-18 23:08:54 +00:00
|
|
|
case ARCH_SET_GS: {
|
2018-11-26 19:55:24 +00:00
|
|
|
if (unlikely(arg2 >= TASK_SIZE_MAX))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
preempt_disable();
|
|
|
|
/*
|
|
|
|
* ARCH_SET_GS has always overwritten the index
|
|
|
|
* and the base. Zero is the most sensible value
|
|
|
|
* to put in the index, and is the only value that
|
|
|
|
* makes any sense if FSGSBASE is unavailable.
|
|
|
|
*/
|
|
|
|
if (task == current) {
|
|
|
|
loadseg(GS, 0);
|
|
|
|
x86_gsbase_write_cpu_inactive(arg2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On non-FSGSBASE systems, save_base_legacy() expects
|
|
|
|
* that we also fill in thread.gsbase.
|
|
|
|
*/
|
|
|
|
task->thread.gsbase = arg2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
task->thread.gsindex = 0;
|
|
|
|
x86_gsbase_write_task(task, arg2);
|
|
|
|
}
|
|
|
|
preempt_enable();
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2018-09-18 23:08:54 +00:00
|
|
|
}
|
|
|
|
case ARCH_SET_FS: {
|
2018-11-26 19:55:24 +00:00
|
|
|
/*
|
|
|
|
* Not strictly needed for %fs, but do it for symmetry
|
|
|
|
* with %gs
|
|
|
|
*/
|
|
|
|
if (unlikely(arg2 >= TASK_SIZE_MAX))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
preempt_disable();
|
|
|
|
/*
|
|
|
|
* Set the selector to 0 for the same reason
|
|
|
|
* as %gs above.
|
|
|
|
*/
|
|
|
|
if (task == current) {
|
|
|
|
loadseg(FS, 0);
|
|
|
|
x86_fsbase_write_cpu(arg2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On non-FSGSBASE systems, save_base_legacy() expects
|
|
|
|
* that we also fill in thread.fsbase.
|
|
|
|
*/
|
|
|
|
task->thread.fsbase = arg2;
|
|
|
|
} else {
|
|
|
|
task->thread.fsindex = 0;
|
|
|
|
x86_fsbase_write_task(task, arg2);
|
|
|
|
}
|
|
|
|
preempt_enable();
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2018-09-18 23:08:54 +00:00
|
|
|
}
|
2008-01-30 12:31:03 +00:00
|
|
|
case ARCH_GET_FS: {
|
2018-09-18 23:08:54 +00:00
|
|
|
unsigned long base = x86_fsbase_read_task(task);
|
2017-03-20 08:16:22 +00:00
|
|
|
|
|
|
|
ret = put_user(base, (unsigned long __user *)arg2);
|
2008-01-30 12:31:03 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-30 12:31:03 +00:00
|
|
|
case ARCH_GET_GS: {
|
2018-09-18 23:08:54 +00:00
|
|
|
unsigned long base = x86_gsbase_read_task(task);
|
2017-03-20 08:16:22 +00:00
|
|
|
|
|
|
|
ret = put_user(base, (unsigned long __user *)arg2);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-05 13:33:05 +00:00
|
|
|
#ifdef CONFIG_CHECKPOINT_RESTORE
|
2016-09-17 00:51:53 +00:00
|
|
|
# ifdef CONFIG_X86_X32_ABI
|
2016-09-05 13:33:05 +00:00
|
|
|
case ARCH_MAP_VDSO_X32:
|
2017-03-20 08:16:22 +00:00
|
|
|
return prctl_map_vdso(&vdso_image_x32, arg2);
|
2016-09-15 06:42:51 +00:00
|
|
|
# endif
|
|
|
|
# if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
|
2016-09-05 13:33:05 +00:00
|
|
|
case ARCH_MAP_VDSO_32:
|
2017-03-20 08:16:22 +00:00
|
|
|
return prctl_map_vdso(&vdso_image_32, arg2);
|
2016-09-15 06:42:51 +00:00
|
|
|
# endif
|
2016-09-05 13:33:05 +00:00
|
|
|
case ARCH_MAP_VDSO_64:
|
2017-03-20 08:16:22 +00:00
|
|
|
return prctl_map_vdso(&vdso_image_64, arg2);
|
2016-09-05 13:33:05 +00:00
|
|
|
#endif
|
2023-03-12 11:26:03 +00:00
|
|
|
#ifdef CONFIG_ADDRESS_MASKING
|
|
|
|
case ARCH_GET_UNTAG_MASK:
|
|
|
|
return put_user(task->mm->context.untag_mask,
|
|
|
|
(unsigned long __user *)arg2);
|
|
|
|
case ARCH_ENABLE_TAGGED_ADDR:
|
|
|
|
return prctl_enable_tagged_addr(task->mm, arg2);
|
2023-03-12 11:26:06 +00:00
|
|
|
case ARCH_FORCE_TAGGED_SVA:
|
2023-04-03 11:10:20 +00:00
|
|
|
if (current != task)
|
|
|
|
return -EINVAL;
|
2023-03-12 11:26:06 +00:00
|
|
|
set_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &task->mm->context.flags);
|
|
|
|
return 0;
|
2023-03-12 11:26:03 +00:00
|
|
|
case ARCH_GET_MAX_TAG_BITS:
|
|
|
|
if (!cpu_feature_enabled(X86_FEATURE_LAM))
|
|
|
|
return put_user(0, (unsigned long __user *)arg2);
|
|
|
|
else
|
|
|
|
return put_user(LAM_U57_BITS, (unsigned long __user *)arg2);
|
|
|
|
#endif
|
2023-06-13 00:10:52 +00:00
|
|
|
case ARCH_SHSTK_ENABLE:
|
|
|
|
case ARCH_SHSTK_DISABLE:
|
|
|
|
case ARCH_SHSTK_LOCK:
|
2023-06-13 00:11:07 +00:00
|
|
|
case ARCH_SHSTK_UNLOCK:
|
2023-06-13 00:11:08 +00:00
|
|
|
case ARCH_SHSTK_STATUS:
|
2023-06-13 00:10:52 +00:00
|
|
|
return shstk_prctl(task, option, arg2);
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
2008-01-30 12:31:03 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-30 12:31:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-03-20 08:16:22 +00:00
|
|
|
SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-03-20 08:16:23 +00:00
|
|
|
long ret;
|
|
|
|
|
|
|
|
ret = do_arch_prctl_64(current, option, arg2);
|
|
|
|
if (ret == -EINVAL)
|
2022-05-12 12:04:08 +00:00
|
|
|
ret = do_arch_prctl_common(option, arg2);
|
2017-03-20 08:16:23 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 08:16:24 +00:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
|
|
|
COMPAT_SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)
|
|
|
|
{
|
2022-05-12 12:04:08 +00:00
|
|
|
return do_arch_prctl_common(option, arg2);
|
2017-03-20 08:16:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-03 09:22:40 +00:00
|
|
|
unsigned long KSTK_ESP(struct task_struct *task)
|
|
|
|
{
|
2015-03-09 18:39:23 +00:00
|
|
|
return task_pt_regs(task)->sp;
|
2009-11-03 09:22:40 +00:00
|
|
|
}
|