From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964834AbbC0PRs (ORCPT ); Fri, 27 Mar 2015 11:17:48 -0400 Received: from mail.skyhub.de ([78.46.96.112]:53563 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbbC0PRp (ORCPT ); Fri, 27 Mar 2015 11:17:45 -0400 Date: Fri, 27 Mar 2015 16:15:55 +0100 From: Borislav Petkov To: Dave Hansen Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, oleg@redhat.com, riel@redhat.com, sbsiddha@gmail.com, luto@amacapital.net, mingo@redhat.com, hpa@zytor.com, fenghua.yu@intel.com Subject: Re: [PATCH 01/17] x86, fpu: wrap get_xsave_addr() to make it safer Message-ID: <20150327151555.GB5517@pd.tnic> References: <20150326183327.64807530@viggo.jf.intel.com> <20150326183334.6D61EDA5@viggo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150326183334.6D61EDA5@viggo.jf.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2015 at 11:33:34AM -0700, Dave Hansen wrote: > > From: Dave Hansen > > The MPX code appears to be saving off the FPU in an unsafe > way. It does not disable preemption or ensure that the > FPU state has been allocated. > > This patch introduces a new helper which will do both of > those things internally. > > Note that this requires a patch from Oleg in order to work > properly. It is currently in tip/x86/fpu. > > > commit f893959b0898bd876673adbeb6798bdf25c034d7 > > Author: Oleg Nesterov > > Date: Fri Mar 13 18:30:30 2015 +0100 > > > > x86/fpu: Don't abuse drop_init_fpu() in flush_thread() > > Signed-off-by: Dave Hansen > Cc: Oleg Nesterov > Cc: bp@alien8.de > Cc: Rik van Riel > Cc: Suresh Siddha > Cc: Andy Lutomirski > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: "H. Peter Anvin" > Cc: Fenghua Yu > Cc: the arch/x86 maintainers > --- > > b/arch/x86/include/asm/xsave.h | 1 + > b/arch/x86/kernel/xsave.c | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff -puN arch/x86/include/asm/xsave.h~tsk_get_xsave_addr arch/x86/include/asm/xsave.h > --- a/arch/x86/include/asm/xsave.h~tsk_get_xsave_addr 2015-03-26 11:27:04.738204327 -0700 > +++ b/arch/x86/include/asm/xsave.h 2015-03-26 11:27:04.743204552 -0700 > @@ -252,6 +252,7 @@ static inline int xrestore_user(struct x > } > > void *get_xsave_addr(struct xsave_struct *xsave, int xstate); > +void *tsk_get_xsave_field(struct task_struct *tsk, int xstate_field); > void setup_xstate_comp(void); > > #endif > diff -puN arch/x86/kernel/xsave.c~tsk_get_xsave_addr arch/x86/kernel/xsave.c > --- a/arch/x86/kernel/xsave.c~tsk_get_xsave_addr 2015-03-26 11:27:04.740204417 -0700 > +++ b/arch/x86/kernel/xsave.c 2015-03-26 11:27:04.744204597 -0700 > @@ -740,3 +740,35 @@ void *get_xsave_addr(struct xsave_struct > return (void *)xsave + xstate_comp_offsets[feature]; > } > EXPORT_SYMBOL_GPL(get_xsave_addr); > + > +/* > + * This wraps up the common operations that need to occur when retrieving > + * data from an xsave struct. It first ensures that the task was actually > + * using the FPU and retrieves the data in to a buffer. It then calculates > + * the offset of the requested field in the buffer. > + * > + * This function is safe to call whether the FPU is in use or not. > + * > + * Inputs: > + * tsk: the task from which we are fetching xsave state > + * xstate: state which is defined in xsave.h (e.g. XSTATE_FP, XSTATE_SSE, I think you mean @xsave_field here? > + * etc.) > + * Output: > + * address of the state in the xsave area. > + */ > +void *tsk_get_xsave_field(struct task_struct *tsk, int xsave_field) > +{ > + union thread_xstate *xstate; > + > + if (!used_math()) > + return NULL; > + /* > + * unlazy_fpu() is poorly named and will actually > + * save the xstate off in to the memory buffer. > + */ > + unlazy_fpu(tsk); > + xstate = tsk->thread.fpu.state; > + > + return get_xsave_addr(&xstate->xsave, xsave_field); > +} > +EXPORT_SYMBOL_GPL(tsk_get_xsave_field); I'm not sure we want to export this to modules... and MPX cannot be built as a module either. So why export it? -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --