Messages in this thread |  | | From | Andy Lutomirski <> | Date | Fri, 10 Apr 2015 12:19:25 -0700 | Subject | Re: [PATCH 8/8] x86: Use rd/wr fs/gs base in arch_prctl |
| |
On Fri, Apr 10, 2015 at 8:50 AM, Andi Kleen <andi@firstfloor.org> wrote: > From: Andi Kleen <ak@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.
It's also necessary on my poor obsolete Sandy Bridge machines :)
> > 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. > > With the new instructions available it prefers to use > them in the context switch, instead of using the old > "use GDT segment rewrite" trick. > > v2: Make kprobes safe > Signed-off-by: Andi Kleen <ak@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 3019c51..1fe4d79 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -534,20 +534,38 @@ unsigned long get_wchan(struct task_struct *p) > return 0; > } > > +static noinline __kprobes void reload_user_gs(unsigned long addr) > +{ > + local_irq_disable(); > + swapgs(); > + loadsegment(gs, 0); > + wrgsbase(addr); > + swapgs(); > + local_irq_enable(); > +}
These names are terrifying. How about write_user_gsbase_and_set_gs_to_zero? (Yes, it's a mouthful.) Or write_user_gs_and_gsbase(unsigned short gs, unsigned long gsbase), which we'll need if we make __switch_to fully correct.
Also, at some point we should fix the fsindex vs fs crap in thread_struct. They should be fsindex and fsbase.
--Andy
|  |