On Mon, Mar 21, 2016 at 9:16 AM, Andi Kleen <a...@firstfloor.org> wrote: > From: Andi Kleen <a...@linux.intel.com> > > Convert arch_prctl to use the new instructions to > change fs/gs if available, instead of using MSRs. > > This is merely a small performance optimization, > no new functionality. > > With the new instructions the syscall is really obsolete, > as everything can be set directly in ring 3. But the syscall > is widely used by existing software, so we still support it. > > The syscall still enforces that the addresses are not > in kernel space, even though that is not needed more. > This is mainly so that the programs written for new CPUs > do not suddenly fail on old CPUs. > > v2: Make kprobes safe > v3: Rename things. > Signed-off-by: Andi Kleen <a...@linux.intel.com> > --- > arch/x86/kernel/process_64.c | 48 > ++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 40 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index 53fa839..5f40517 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -530,20 +530,38 @@ void set_personality_ia32(bool x32) > } > EXPORT_SYMBOL_GPL(set_personality_ia32); > > +static noinline __kprobes void reload_user_gs(unsigned long addr) > +{ > + local_irq_disable(); > + swapgs(); > + loadsegment(gs, 0); > + wrgsbase(addr); > + swapgs(); > + local_irq_enable(); > +}
The actual operation this does is to set the selector to zero and the base to the specified value. Can you give it a name that makes it clear (e.g. zero_user_gs_and_set_base)? I'm also wondering whether it would make sense to move the cpu_has into these helpers rather than putting it in the callers. --Andy