Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757692AbcCUSSP (ORCPT ); Mon, 21 Mar 2016 14:18:15 -0400 Received: from mail-ob0-f176.google.com ([209.85.214.176]:33387 "EHLO mail-ob0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757137AbcCUSSO (ORCPT ); Mon, 21 Mar 2016 14:18:14 -0400 MIME-Version: 1.0 In-Reply-To: <1458576969-13309-7-git-send-email-andi@firstfloor.org> References: <1458576969-13309-1-git-send-email-andi@firstfloor.org> <1458576969-13309-7-git-send-email-andi@firstfloor.org> From: Andy Lutomirski Date: Mon, 21 Mar 2016 11:17:54 -0700 Message-ID: Subject: Re: [PATCH 6/9] x86: Use rd/wr fs/gs base in arch_prctl To: Andi Kleen Cc: X86 ML , "linux-kernel@vger.kernel.org" , Andi Kleen Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1771 Lines: 51 On Mon, Mar 21, 2016 at 9:16 AM, Andi Kleen wrote: > From: Andi Kleen > > 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 > --- > 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