Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753214AbbEESFp (ORCPT ); Tue, 5 May 2015 14:05:45 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:35587 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031808AbbEER7n (ORCPT ); Tue, 5 May 2015 13:59:43 -0400 From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Thomas Gleixner Subject: [PATCH 191/208] x86/fpu: Generalize 'init_xstate_ctx' Date: Tue, 5 May 2015 19:58:15 +0200 Message-Id: <1430848712-28064-31-git-send-email-mingo@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430848712-28064-1-git-send-email-mingo@kernel.org> References: <1430848712-28064-1-git-send-email-mingo@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6327 Lines: 186 So the handling of init_xstate_ctx has a layering violation: both 'struct xsave_struct' and 'union thread_xstate' have a 'struct i387_fxsave_struct' member: xsave_struct::i387 thread_xstate::fxsave The handling of init_xstate_ctx is generic, it is used on all CPUs, with or without XSAVE instruction. So it's confusing how the generic code passes around and handles an XSAVE specific format. What we really want is for init_xstate_ctx to be a proper fpstate and we use its ::fxsave and ::xsave members, as appropriate. Since the xsave_struct::i387 and thread_xstate::fxsave aliases each other this is not a functional problem. So implement this, and move init_xstate_ctx to the generic FPU code in the process. Also, since init_xstate_ctx is not XSAVE specific anymore, rename it to init_fpstate, and mark it __read_mostly, because it's only modified once during bootup, and used as a reference fpstate later on. There's no change in functionality. Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/include/asm/fpu/internal.h | 6 ++++-- arch/x86/include/asm/fpu/xstate.h | 1 - arch/x86/kernel/fpu/core.c | 6 ++++++ arch/x86/kernel/fpu/init.c | 2 +- arch/x86/kernel/fpu/xstate.c | 19 +++++++------------ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index b74aa4329aeb..792fdbe64179 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -22,6 +22,8 @@ extern unsigned int mxcsr_feature_mask; +extern union thread_xstate init_fpstate; + extern void fpu__init_cpu(void); extern void fpu__init_system_xstate(void); extern void fpu__init_cpu_xstate(void); @@ -342,9 +344,9 @@ static inline void fpregs_deactivate(struct fpu *fpu) static inline void restore_init_xstate(void) { if (use_xsave()) - xrstor_state(&init_xstate_ctx, -1); + xrstor_state(&init_fpstate.xsave, -1); else - fxrstor_checking(&init_xstate_ctx.i387); + fxrstor_checking(&init_fpstate.fxsave); } /* diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h index afd21329c585..3051280887b8 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h @@ -37,7 +37,6 @@ extern unsigned int xstate_size; extern u64 xfeatures_mask; extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS]; -extern struct xsave_struct init_xstate_ctx; extern void update_regset_xstate_info(unsigned int size, u64 xstate_mask); diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 2642a1ebed2a..43c3f40aa447 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -13,6 +13,12 @@ #include /* + * Represents the initial FPU state. It's mostly (but not completely) zeroes, + * depending on the FPU hardware format: + */ +union thread_xstate init_fpstate __read_mostly; + +/* * Track whether the kernel is using the FPU state * currently. * diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 5a7e57078935..93bc11a5812c 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -121,7 +121,7 @@ static void fpu__init_system_generic(void) * Set up the legacy init FPU context. (xstate init might overwrite this * with a more modern format, if the CPU supports it.) */ - fpstate_init_fxstate(&init_xstate_ctx.i387); + fpstate_init_fxstate(&init_fpstate.fxsave); fpu__init_system_mxcsr(); } diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index afbd58277430..527d4bf4f304 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -31,11 +31,6 @@ static const char *xfeature_names[] = */ u64 xfeatures_mask __read_mostly; -/* - * Represents init state for the supported extended state. - */ -struct xsave_struct init_xstate_ctx; - static struct _fpx_sw_bytes fx_sw_reserved, fx_sw_reserved_ia32; static unsigned int xstate_offsets[XFEATURES_NR_MAX], xstate_sizes[XFEATURES_NR_MAX]; static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8]; @@ -150,7 +145,7 @@ void fpstate_sanitize_xstate(struct fpu *fpu) int size = xstate_sizes[feature_bit]; memcpy((void *)fx + offset, - (void *)&init_xstate_ctx + offset, + (void *)&init_fpstate.xsave + offset, size); } @@ -377,12 +372,12 @@ static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only) if (use_xsave()) { if ((unsigned long)buf % 64 || fx_only) { u64 init_bv = xfeatures_mask & ~XSTATE_FPSSE; - xrstor_state(&init_xstate_ctx, init_bv); + xrstor_state(&init_fpstate.xsave, init_bv); return fxrstor_user(buf); } else { u64 init_bv = xfeatures_mask & ~xbv; if (unlikely(init_bv)) - xrstor_state(&init_xstate_ctx, init_bv); + xrstor_state(&init_fpstate.xsave, init_bv); return xrestore_user(buf, xbv); } } else if (use_fxsr()) { @@ -665,20 +660,20 @@ static void setup_init_fpu_buf(void) print_xstate_features(); if (cpu_has_xsaves) { - init_xstate_ctx.header.xcomp_bv = (u64)1 << 63 | xfeatures_mask; - init_xstate_ctx.header.xfeatures = xfeatures_mask; + init_fpstate.xsave.header.xcomp_bv = (u64)1 << 63 | xfeatures_mask; + init_fpstate.xsave.header.xfeatures = xfeatures_mask; } /* * Init all the features state with header_bv being 0x0 */ - xrstor_state_booting(&init_xstate_ctx, -1); + xrstor_state_booting(&init_fpstate.xsave, -1); /* * Dump the init state again. This is to identify the init state * of any feature which is not represented by all zero's. */ - xsave_state_booting(&init_xstate_ctx); + xsave_state_booting(&init_fpstate.xsave); } /* -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/