linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] x86/fpu: FPU init code bugfixes
@ 2016-01-06 22:24 yu-cheng yu
  2016-01-06 22:24 ` [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing yu-cheng yu
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: yu-cheng yu @ 2016-01-06 22:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: yu-cheng yu, x86, H. Peter Anvin, Thomas Gleixner, Dave Hansen,
	Ingo Molnar, Borislav Petkov, Sai Praneeth Prakhya,
	Ravi V. Shankar, Fenghua Yu

The function fpu__init_system() is executed before parse_early_param().
This causes wrong fpu configuration. In addition, there are three related
issues:

  1. XGETBV1 is enabled when noxsave is given
  2. MPX is enabled when eagerfpu=off is given
  3. AVX is enabled when eagerfpu=off is given

  Issues 1 and 3 are existing bugs. Issue 2 is a fallout from the
  command-line parsing move.

The following four patches fix these issues.

yu-cheng yu (4):
  x86/fpu: Fix early fpu command-line parsing.
  x86/fpu: Disable XGETBV1 when no XSAVE.
  x86/fpu: Disable MPX when eagerfpu is off.
  x86/fpu: Disable AVX when eagerfpu is off.

 arch/x86/include/asm/fpu/internal.h |   1 +
 arch/x86/include/asm/fpu/xstate.h   |  11 +--
 arch/x86/kernel/fpu/init.c          | 161 +++++++++++++++++++-----------------
 arch/x86/kernel/fpu/xstate.c        |   4 +-
 4 files changed, 92 insertions(+), 85 deletions(-)

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: x86@kernel.org
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
-- 
1.9.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing
  2016-01-06 22:24 [PATCH 0/4] x86/fpu: FPU init code bugfixes yu-cheng yu
@ 2016-01-06 22:24 ` yu-cheng yu
  2016-01-12 12:00   ` [tip:x86/asm] x86/fpu: Fix early FPU " tip-bot for yu-cheng yu
  2016-01-06 22:24 ` [PATCH 2/4] x86/fpu: Disable XGETBV1 when no XSAVE yu-cheng yu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: yu-cheng yu @ 2016-01-06 22:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: yu-cheng yu, x86, H. Peter Anvin, Thomas Gleixner, Dave Hansen,
	Ingo Molnar, Borislav Petkov, Sai Praneeth Prakhya,
	Ravi V. Shankar, Fenghua Yu

The function fpu__init_system() is executed before parse_early_param().
This causes wrong fpu configuration. This patch fixes this issue by
parsing boot_command_line in the beginning of fpu__init_system().

With all four patches in this series, each parameter disables features as
the following:

eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
no387: fpu
nofxsr: fxsr, fxsropt, xmm
noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512, mpx, xgetbv1
noxsaveopt: xsaveopt
noxsaves: xsaves

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: x86@kernel.org
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++-----------------------------
 1 file changed, 38 insertions(+), 71 deletions(-)

diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index be39b5f..057b73e 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -3,8 +3,11 @@
  */
 #include <asm/fpu/internal.h>
 #include <asm/tlbflush.h>
+#include <asm/setup.h>
+#include <asm/cmdline.h>
 
 #include <linux/sched.h>
+#include <linux/init.h>
 
 /*
  * Initialize the TS bit in CR0 according to the style of context-switches
@@ -261,18 +264,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
  */
 static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO;
 
-static int __init eager_fpu_setup(char *s)
-{
-	if (!strcmp(s, "on"))
-		eagerfpu = ENABLE;
-	else if (!strcmp(s, "off"))
-		eagerfpu = DISABLE;
-	else if (!strcmp(s, "auto"))
-		eagerfpu = AUTO;
-	return 1;
-}
-__setup("eagerfpu=", eager_fpu_setup);
-
 /*
  * Pick the FPU context switching strategy:
  */
@@ -307,11 +298,46 @@ static void __init fpu__init_system_ctx_switch(void)
 }
 
 /*
+ * We parse fpu parameters early because fpu__init_system() is executed
+ * before parse_early_param().
+ */
+static void __init fpu__init_parse_early_param(void)
+{
+	/*
+	 * No need to check "eagerfpu=auto" again, since it is the
+	 * initial default.
+	 */
+	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
+		eagerfpu = DISABLE;
+	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
+		eagerfpu = ENABLE;
+
+	if (cmdline_find_option_bool(boot_command_line, "no387"))
+		setup_clear_cpu_cap(X86_FEATURE_FPU);
+
+	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+		setup_clear_cpu_cap(X86_FEATURE_FXSR);
+		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
+		setup_clear_cpu_cap(X86_FEATURE_XMM);
+	}
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
+		fpu__xstate_clear_all_cpu_caps();
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
+		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
+		setup_clear_cpu_cap(X86_FEATURE_XSAVES);
+}
+
+/*
  * Called on the boot CPU once per system bootup, to set up the initial
  * FPU state that is later cloned into all processes:
  */
 void __init fpu__init_system(struct cpuinfo_x86 *c)
 {
+	fpu__init_parse_early_param();
 	fpu__init_system_early_generic(c);
 
 	/*
@@ -335,62 +361,3 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)
 
 	fpu__init_system_ctx_switch();
 }
-
-/*
- * Boot parameter to turn off FPU support and fall back to math-emu:
- */
-static int __init no_387(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_FPU);
-	return 1;
-}
-__setup("no387", no_387);
-
-/*
- * Disable all xstate CPU features:
- */
-static int __init x86_noxsave_setup(char *s)
-{
-	if (strlen(s))
-		return 0;
-
-	fpu__xstate_clear_all_cpu_caps();
-
-	return 1;
-}
-__setup("noxsave", x86_noxsave_setup);
-
-/*
- * Disable the XSAVEOPT instruction specifically:
- */
-static int __init x86_noxsaveopt_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
-
-	return 1;
-}
-__setup("noxsaveopt", x86_noxsaveopt_setup);
-
-/*
- * Disable the XSAVES instruction:
- */
-static int __init x86_noxsaves_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVES);
-
-	return 1;
-}
-__setup("noxsaves", x86_noxsaves_setup);
-
-/*
- * Disable FX save/restore and SSE support:
- */
-static int __init x86_nofxsr_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_FXSR);
-	setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
-	setup_clear_cpu_cap(X86_FEATURE_XMM);
-
-	return 1;
-}
-__setup("nofxsr", x86_nofxsr_setup);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/4] x86/fpu: Disable XGETBV1 when no XSAVE
  2016-01-06 22:24 [PATCH 0/4] x86/fpu: FPU init code bugfixes yu-cheng yu
  2016-01-06 22:24 ` [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing yu-cheng yu
@ 2016-01-06 22:24 ` yu-cheng yu
  2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu
  2016-01-06 22:24 ` [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off yu-cheng yu
  2016-01-06 22:24 ` [PATCH 4/4] x86/fpu: Disable AVX " yu-cheng yu
  3 siblings, 1 reply; 13+ messages in thread
From: yu-cheng yu @ 2016-01-06 22:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: yu-cheng yu, x86, H. Peter Anvin, Thomas Gleixner, Dave Hansen,
	Ingo Molnar, Borislav Petkov, Sai Praneeth Prakhya,
	Ravi V. Shankar, Fenghua Yu

When "noxsave" is given as a command-line input, the kernel should disable
XGETBV1. This issue currently does not cause any actual problems. XGETBV1
is only useful if we have something using the 'init optimization' (i.e.
xsaveopt, xsaves). We already clear both of those in
fpu__xstate_clear_all_cpu_caps(). But this is good for completeness.

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Cc: x86@kernel.org
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/x86/kernel/fpu/xstate.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 70fc312..b27d3b6 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -52,6 +52,7 @@ void fpu__xstate_clear_all_cpu_caps(void)
 	setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
 	setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
 	setup_clear_cpu_cap(X86_FEATURE_MPX);
+	setup_clear_cpu_cap(X86_FEATURE_XGETBV1);
 }
 
 /*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off
  2016-01-06 22:24 [PATCH 0/4] x86/fpu: FPU init code bugfixes yu-cheng yu
  2016-01-06 22:24 ` [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing yu-cheng yu
  2016-01-06 22:24 ` [PATCH 2/4] x86/fpu: Disable XGETBV1 when no XSAVE yu-cheng yu
@ 2016-01-06 22:24 ` yu-cheng yu
  2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu
  2016-01-06 22:24 ` [PATCH 4/4] x86/fpu: Disable AVX " yu-cheng yu
  3 siblings, 1 reply; 13+ messages in thread
From: yu-cheng yu @ 2016-01-06 22:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: yu-cheng yu, x86, H. Peter Anvin, Thomas Gleixner, Dave Hansen,
	Ingo Molnar, Borislav Petkov, Sai Praneeth Prakhya,
	Ravi V. Shankar, Fenghua Yu

This issue is a fallout from the command-line parsing move.

When "eagerfpu=off" is given as a command-line input, the kernel should
disable MPX support. The decision for turning off MPX was made in
fpu__init_system_ctx_switch(), which is after the selection of the XSAVE
format. This patch fixes it by getting that decision done earlier in
fpu__init_system_xstate().

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: x86@kernel.org
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/x86/include/asm/fpu/internal.h |  1 +
 arch/x86/kernel/fpu/init.c          | 56 +++++++++++++++++++++++++++++--------
 arch/x86/kernel/fpu/xstate.c        |  3 +-
 3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 3c3550c..6b07a842 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -42,6 +42,7 @@ extern void fpu__init_cpu_xstate(void);
 extern void fpu__init_system(struct cpuinfo_x86 *c);
 extern void fpu__init_check_bugs(void);
 extern void fpu__resume_cpu(void);
+extern u64 fpu__get_supported_xfeatures_mask(void);
 
 /*
  * Debugging facility:
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 057b73e..aad53cc 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -265,7 +265,45 @@ static void __init fpu__init_system_xstate_size_legacy(void)
 static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO;
 
 /*
+ * Find supported xfeatures based on cpu features and command-line input.
+ * This must be called after fpu__init_parse_early_param() is called and
+ * xfeatures_mask is enumerated.
+ */
+u64 __init fpu__get_supported_xfeatures_mask(void)
+{
+	/* Support all xfeatures known to us */
+	if (eagerfpu != DISABLE)
+		return XCNTXT_MASK;
+
+	/* Warning of xfeatures being disabled for no eagerfpu mode */
+	if (xfeatures_mask & XFEATURE_MASK_EAGER) {
+		pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n",
+			xfeatures_mask & XFEATURE_MASK_EAGER);
+	}
+
+	/* Return a mask that masks out all features requiring eagerfpu mode */
+	return ~XFEATURE_MASK_EAGER;
+}
+
+/*
+ * Disable features dependent on eagerfpu.
+ */
+static void __init fpu__clear_eager_fpu_features(void)
+{
+	setup_clear_cpu_cap(X86_FEATURE_MPX);
+}
+
+/*
  * Pick the FPU context switching strategy:
+ *
+ * When eagerfpu is AUTO or ENABLE, we ensure it is ENABLE if either of
+ * the following is true:
+ *
+ * (1) the cpu has xsaveopt, as it has the optimization and doing eager
+ *     FPU switching has a relatively low cost compared to a plain xsave;
+ * (2) the cpu has xsave features (e.g. MPX) that depend on eager FPU
+ *     switching. Should the kernel boot with noxsaveopt, we support MPX
+ *     with eager FPU switching at a higher cost.
  */
 static void __init fpu__init_system_ctx_switch(void)
 {
@@ -277,19 +315,11 @@ static void __init fpu__init_system_ctx_switch(void)
 	WARN_ON_FPU(current->thread.fpu.fpstate_active);
 	current_thread_info()->status = 0;
 
-	/* Auto enable eagerfpu for xsaveopt */
 	if (cpu_has_xsaveopt && eagerfpu != DISABLE)
 		eagerfpu = ENABLE;
 
-	if (xfeatures_mask & XFEATURE_MASK_EAGER) {
-		if (eagerfpu == DISABLE) {
-			pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n",
-			       xfeatures_mask & XFEATURE_MASK_EAGER);
-			xfeatures_mask &= ~XFEATURE_MASK_EAGER;
-		} else {
-			eagerfpu = ENABLE;
-		}
-	}
+	if (xfeatures_mask & XFEATURE_MASK_EAGER)
+		eagerfpu = ENABLE;
 
 	if (eagerfpu == ENABLE)
 		setup_force_cpu_cap(X86_FEATURE_EAGER_FPU);
@@ -307,10 +337,12 @@ static void __init fpu__init_parse_early_param(void)
 	 * No need to check "eagerfpu=auto" again, since it is the
 	 * initial default.
 	 */
-	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
+	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) {
 		eagerfpu = DISABLE;
-	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
+		fpu__clear_eager_fpu_features();
+	} else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on")) {
 		eagerfpu = ENABLE;
+	}
 
 	if (cmdline_find_option_bool(boot_command_line, "no387"))
 		setup_clear_cpu_cap(X86_FEATURE_FPU);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index b27d3b6..8fb473b 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -633,8 +633,7 @@ void __init fpu__init_system_xstate(void)
 		BUG();
 	}
 
-	/* Support only the state known to the OS: */
-	xfeatures_mask = xfeatures_mask & XCNTXT_MASK;
+	xfeatures_mask &= fpu__get_supported_xfeatures_mask();
 
 	/* Enable xstate instructions to be able to continue with initialization: */
 	fpu__init_cpu_xstate();
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/4] x86/fpu: Disable AVX when eagerfpu is off
  2016-01-06 22:24 [PATCH 0/4] x86/fpu: FPU init code bugfixes yu-cheng yu
                   ` (2 preceding siblings ...)
  2016-01-06 22:24 ` [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off yu-cheng yu
@ 2016-01-06 22:24 ` yu-cheng yu
  2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu
  3 siblings, 1 reply; 13+ messages in thread
From: yu-cheng yu @ 2016-01-06 22:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: yu-cheng yu, x86, H. Peter Anvin, Thomas Gleixner, Dave Hansen,
	Ingo Molnar, Borislav Petkov, Sai Praneeth Prakhya,
	Ravi V. Shankar, Fenghua Yu

When "eagerfpu=off" is given as a command-line input, the kernel should
disable AVX support.

The Task Switched bit used for lazy context switching does not support
AVX. If AVX is enabled without eagerfpu context switching, one task's AVX
state could become corrupted or leak to other tasks. This is a bug and has
bad security implications.

This only affects systems that have AVX/AVX2/AVX512 and this issue will be
found only when one actually uses AVX/AVX2/AVX512 _AND_ does eagerfpu=off.

Referece: Intel Software Developer's Manual Vol. 3A

Sec. 2.5 Control Registers:
TS Task Switched bit (bit 3 of CR0) -- Allows the saving of the x87 FPU/
MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch to be delayed until
an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed
by the new task.

Sec. 13.4.1 Using the TS Flag to Control the Saving of the X87 FPU and SSE
State
When the TS flag is set, the processor monitors the instruction stream for
x87 FPU, MMX, SSE instructions. When the processor detects one of these
instructions, it raises a device-not-available exeception (#NM) prior to
executing the instruction.

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: x86@kernel.org
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
---
 arch/x86/include/asm/fpu/xstate.h | 11 ++++++-----
 arch/x86/kernel/fpu/init.c        |  6 ++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index 3a6c89b..af30fde 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -20,15 +20,16 @@
 
 /* Supported features which support lazy state saving */
 #define XFEATURE_MASK_LAZY	(XFEATURE_MASK_FP | \
-				 XFEATURE_MASK_SSE | \
+				 XFEATURE_MASK_SSE)
+
+/* Supported features which require eager state saving */
+#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | \
+				 XFEATURE_MASK_BNDCSR | \
 				 XFEATURE_MASK_YMM | \
-				 XFEATURE_MASK_OPMASK |	\
+				 XFEATURE_MASK_OPMASK | \
 				 XFEATURE_MASK_ZMM_Hi256 | \
 				 XFEATURE_MASK_Hi16_ZMM)
 
-/* Supported features which require eager state saving */
-#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)
-
 /* All currently supported features */
 #define XCNTXT_MASK	(XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
 
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index aad53cc..e7e3dbfdb 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -291,6 +291,12 @@ u64 __init fpu__get_supported_xfeatures_mask(void)
 static void __init fpu__clear_eager_fpu_features(void)
 {
 	setup_clear_cpu_cap(X86_FEATURE_MPX);
+	setup_clear_cpu_cap(X86_FEATURE_AVX);
+	setup_clear_cpu_cap(X86_FEATURE_AVX2);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512F);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512PF);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
 }
 
 /*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
  2016-01-06 22:24 ` [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing yu-cheng yu
@ 2016-01-12 12:00   ` tip-bot for yu-cheng yu
  2016-01-15 20:28     ` Borislav Petkov
  0 siblings, 1 reply; 13+ messages in thread
From: tip-bot for yu-cheng yu @ 2016-01-12 12:00 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, linux-kernel, torvalds, ravi.v.shankar, yu-cheng.yu,
	tglx, bp, oleg, dave.hansen, mingo, fenghua.yu,
	quentin.casasnovas, bp, hpa, sai.praneeth.prakhya, luto

Commit-ID:  4f81cbafcce2c603db7865e9d0e461f7947d77d4
Gitweb:     http://git.kernel.org/tip/4f81cbafcce2c603db7865e9d0e461f7947d77d4
Author:     yu-cheng yu <yu-cheng.yu@intel.com>
AuthorDate: Wed, 6 Jan 2016 14:24:51 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 12 Jan 2016 11:51:20 +0100

x86/fpu: Fix early FPU command-line parsing

The function fpu__init_system() is executed before
parse_early_param(). This causes wrong FPU configuration. This
patch fixes this issue by parsing boot_command_line in the
beginning of fpu__init_system().

With all four patches in this series, each parameter disables
features as the following:

eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
no387: fpu
nofxsr: fxsr, fxsropt, xmm
noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512,
mpx, xgetbv1 noxsaveopt: xsaveopt
noxsaves: xsaves

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/1452119094-7252-2-git-send-email-yu-cheng.yu@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++-----------------------------
 1 file changed, 38 insertions(+), 71 deletions(-)

diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 7b2978a..3a45fcd 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -3,8 +3,11 @@
  */
 #include <asm/fpu/internal.h>
 #include <asm/tlbflush.h>
+#include <asm/setup.h>
+#include <asm/cmdline.h>
 
 #include <linux/sched.h>
+#include <linux/init.h>
 
 /*
  * Initialize the TS bit in CR0 according to the style of context-switches
@@ -270,18 +273,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
  */
 static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO;
 
-static int __init eager_fpu_setup(char *s)
-{
-	if (!strcmp(s, "on"))
-		eagerfpu = ENABLE;
-	else if (!strcmp(s, "off"))
-		eagerfpu = DISABLE;
-	else if (!strcmp(s, "auto"))
-		eagerfpu = AUTO;
-	return 1;
-}
-__setup("eagerfpu=", eager_fpu_setup);
-
 /*
  * Pick the FPU context switching strategy:
  */
@@ -316,11 +307,46 @@ static void __init fpu__init_system_ctx_switch(void)
 }
 
 /*
+ * We parse fpu parameters early because fpu__init_system() is executed
+ * before parse_early_param().
+ */
+static void __init fpu__init_parse_early_param(void)
+{
+	/*
+	 * No need to check "eagerfpu=auto" again, since it is the
+	 * initial default.
+	 */
+	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
+		eagerfpu = DISABLE;
+	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
+		eagerfpu = ENABLE;
+
+	if (cmdline_find_option_bool(boot_command_line, "no387"))
+		setup_clear_cpu_cap(X86_FEATURE_FPU);
+
+	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+		setup_clear_cpu_cap(X86_FEATURE_FXSR);
+		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
+		setup_clear_cpu_cap(X86_FEATURE_XMM);
+	}
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
+		fpu__xstate_clear_all_cpu_caps();
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
+		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
+
+	if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
+		setup_clear_cpu_cap(X86_FEATURE_XSAVES);
+}
+
+/*
  * Called on the boot CPU once per system bootup, to set up the initial
  * FPU state that is later cloned into all processes:
  */
 void __init fpu__init_system(struct cpuinfo_x86 *c)
 {
+	fpu__init_parse_early_param();
 	fpu__init_system_early_generic(c);
 
 	/*
@@ -344,62 +370,3 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)
 
 	fpu__init_system_ctx_switch();
 }
-
-/*
- * Boot parameter to turn off FPU support and fall back to math-emu:
- */
-static int __init no_387(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_FPU);
-	return 1;
-}
-__setup("no387", no_387);
-
-/*
- * Disable all xstate CPU features:
- */
-static int __init x86_noxsave_setup(char *s)
-{
-	if (strlen(s))
-		return 0;
-
-	fpu__xstate_clear_all_cpu_caps();
-
-	return 1;
-}
-__setup("noxsave", x86_noxsave_setup);
-
-/*
- * Disable the XSAVEOPT instruction specifically:
- */
-static int __init x86_noxsaveopt_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
-
-	return 1;
-}
-__setup("noxsaveopt", x86_noxsaveopt_setup);
-
-/*
- * Disable the XSAVES instruction:
- */
-static int __init x86_noxsaves_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVES);
-
-	return 1;
-}
-__setup("noxsaves", x86_noxsaves_setup);
-
-/*
- * Disable FX save/restore and SSE support:
- */
-static int __init x86_nofxsr_setup(char *s)
-{
-	setup_clear_cpu_cap(X86_FEATURE_FXSR);
-	setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
-	setup_clear_cpu_cap(X86_FEATURE_XMM);
-
-	return 1;
-}
-__setup("nofxsr", x86_nofxsr_setup);

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:x86/asm] x86/fpu: Disable XGETBV1 when no XSAVE
  2016-01-06 22:24 ` [PATCH 2/4] x86/fpu: Disable XGETBV1 when no XSAVE yu-cheng yu
@ 2016-01-12 12:01   ` tip-bot for yu-cheng yu
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for yu-cheng yu @ 2016-01-12 12:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, peterz, bp, tglx, mingo, bp, dave.hansen, luto,
	ravi.v.shankar, dave.hansen, sai.praneeth.prakhya, yu-cheng.yu,
	quentin.casasnovas, hpa, linux-kernel, oleg, fenghua.yu

Commit-ID:  eb7c5f872e697b0aebd846cf3a3328d71e9decb2
Gitweb:     http://git.kernel.org/tip/eb7c5f872e697b0aebd846cf3a3328d71e9decb2
Author:     yu-cheng yu <yu-cheng.yu@intel.com>
AuthorDate: Wed, 6 Jan 2016 14:24:52 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 12 Jan 2016 11:51:21 +0100

x86/fpu: Disable XGETBV1 when no XSAVE

When "noxsave" is given as a command-line input, the kernel
should disable XGETBV1. This issue currently does not cause any
actual problems. XGETBV1 is only useful if we have something
using the 'init optimization' (i.e. xsaveopt, xsaves). We
already clear both of those in fpu__xstate_clear_all_cpu_caps().
But this is good for completeness.

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/1452119094-7252-3-git-send-email-yu-cheng.yu@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/fpu/xstate.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 40f1002..d489f27 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -52,6 +52,7 @@ void fpu__xstate_clear_all_cpu_caps(void)
 	setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
 	setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
 	setup_clear_cpu_cap(X86_FEATURE_MPX);
+	setup_clear_cpu_cap(X86_FEATURE_XGETBV1);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:x86/asm] x86/fpu: Disable MPX when eagerfpu is off
  2016-01-06 22:24 ` [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off yu-cheng yu
@ 2016-01-12 12:01   ` tip-bot for yu-cheng yu
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for yu-cheng yu @ 2016-01-12 12:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, peterz, ravi.v.shankar, quentin.casasnovas, bp,
	luto, torvalds, bp, mingo, sai.praneeth.prakhya, dave.hansen,
	yu-cheng.yu, fenghua.yu, hpa, oleg, tglx

Commit-ID:  a5fe93a549c54838063d2952dd9643b0b18aa67f
Gitweb:     http://git.kernel.org/tip/a5fe93a549c54838063d2952dd9643b0b18aa67f
Author:     yu-cheng yu <yu-cheng.yu@intel.com>
AuthorDate: Wed, 6 Jan 2016 14:24:53 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 12 Jan 2016 11:51:21 +0100

x86/fpu: Disable MPX when eagerfpu is off

This issue is a fallout from the command-line parsing move.

When "eagerfpu=off" is given as a command-line input, the kernel
should disable MPX support. The decision for turning off MPX was
made in fpu__init_system_ctx_switch(), which is after the
selection of the XSAVE format. This patch fixes it by getting
that decision done earlier in fpu__init_system_xstate().

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/1452119094-7252-4-git-send-email-yu-cheng.yu@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/internal.h |  1 +
 arch/x86/kernel/fpu/init.c          | 56 +++++++++++++++++++++++++++++--------
 arch/x86/kernel/fpu/xstate.c        |  3 +-
 3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index eadcdd5..0fd440d 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -42,6 +42,7 @@ extern void fpu__init_cpu_xstate(void);
 extern void fpu__init_system(struct cpuinfo_x86 *c);
 extern void fpu__init_check_bugs(void);
 extern void fpu__resume_cpu(void);
+extern u64 fpu__get_supported_xfeatures_mask(void);
 
 /*
  * Debugging facility:
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 3a45fcd..f0ab368 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -274,7 +274,45 @@ static void __init fpu__init_system_xstate_size_legacy(void)
 static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO;
 
 /*
+ * Find supported xfeatures based on cpu features and command-line input.
+ * This must be called after fpu__init_parse_early_param() is called and
+ * xfeatures_mask is enumerated.
+ */
+u64 __init fpu__get_supported_xfeatures_mask(void)
+{
+	/* Support all xfeatures known to us */
+	if (eagerfpu != DISABLE)
+		return XCNTXT_MASK;
+
+	/* Warning of xfeatures being disabled for no eagerfpu mode */
+	if (xfeatures_mask & XFEATURE_MASK_EAGER) {
+		pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n",
+			xfeatures_mask & XFEATURE_MASK_EAGER);
+	}
+
+	/* Return a mask that masks out all features requiring eagerfpu mode */
+	return ~XFEATURE_MASK_EAGER;
+}
+
+/*
+ * Disable features dependent on eagerfpu.
+ */
+static void __init fpu__clear_eager_fpu_features(void)
+{
+	setup_clear_cpu_cap(X86_FEATURE_MPX);
+}
+
+/*
  * Pick the FPU context switching strategy:
+ *
+ * When eagerfpu is AUTO or ENABLE, we ensure it is ENABLE if either of
+ * the following is true:
+ *
+ * (1) the cpu has xsaveopt, as it has the optimization and doing eager
+ *     FPU switching has a relatively low cost compared to a plain xsave;
+ * (2) the cpu has xsave features (e.g. MPX) that depend on eager FPU
+ *     switching. Should the kernel boot with noxsaveopt, we support MPX
+ *     with eager FPU switching at a higher cost.
  */
 static void __init fpu__init_system_ctx_switch(void)
 {
@@ -286,19 +324,11 @@ static void __init fpu__init_system_ctx_switch(void)
 	WARN_ON_FPU(current->thread.fpu.fpstate_active);
 	current_thread_info()->status = 0;
 
-	/* Auto enable eagerfpu for xsaveopt */
 	if (boot_cpu_has(X86_FEATURE_XSAVEOPT) && eagerfpu != DISABLE)
 		eagerfpu = ENABLE;
 
-	if (xfeatures_mask & XFEATURE_MASK_EAGER) {
-		if (eagerfpu == DISABLE) {
-			pr_err("x86/fpu: eagerfpu switching disabled, disabling the following xstate features: 0x%llx.\n",
-			       xfeatures_mask & XFEATURE_MASK_EAGER);
-			xfeatures_mask &= ~XFEATURE_MASK_EAGER;
-		} else {
-			eagerfpu = ENABLE;
-		}
-	}
+	if (xfeatures_mask & XFEATURE_MASK_EAGER)
+		eagerfpu = ENABLE;
 
 	if (eagerfpu == ENABLE)
 		setup_force_cpu_cap(X86_FEATURE_EAGER_FPU);
@@ -316,10 +346,12 @@ static void __init fpu__init_parse_early_param(void)
 	 * No need to check "eagerfpu=auto" again, since it is the
 	 * initial default.
 	 */
-	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
+	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) {
 		eagerfpu = DISABLE;
-	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
+		fpu__clear_eager_fpu_features();
+	} else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on")) {
 		eagerfpu = ENABLE;
+	}
 
 	if (cmdline_find_option_bool(boot_command_line, "no387"))
 		setup_clear_cpu_cap(X86_FEATURE_FPU);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index d489f27..d425cda5 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -633,8 +633,7 @@ void __init fpu__init_system_xstate(void)
 		BUG();
 	}
 
-	/* Support only the state known to the OS: */
-	xfeatures_mask = xfeatures_mask & XCNTXT_MASK;
+	xfeatures_mask &= fpu__get_supported_xfeatures_mask();
 
 	/* Enable xstate instructions to be able to continue with initialization: */
 	fpu__init_cpu_xstate();

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:x86/asm] x86/fpu: Disable AVX when eagerfpu is off
  2016-01-06 22:24 ` [PATCH 4/4] x86/fpu: Disable AVX " yu-cheng yu
@ 2016-01-12 12:01   ` tip-bot for yu-cheng yu
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for yu-cheng yu @ 2016-01-12 12:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: luto, bp, bp, yu-cheng.yu, dave.hansen, tglx, fenghua.yu, mingo,
	peterz, quentin.casasnovas, linux-kernel, oleg, hpa,
	sai.praneeth.prakhya, ravi.v.shankar, torvalds

Commit-ID:  394db20ca240741a08d472173db13d6f6a6e5a28
Gitweb:     http://git.kernel.org/tip/394db20ca240741a08d472173db13d6f6a6e5a28
Author:     yu-cheng yu <yu-cheng.yu@intel.com>
AuthorDate: Wed, 6 Jan 2016 14:24:54 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 12 Jan 2016 11:51:21 +0100

x86/fpu: Disable AVX when eagerfpu is off

When "eagerfpu=off" is given as a command-line input, the kernel
should disable AVX support.

The Task Switched bit used for lazy context switching does not
support AVX. If AVX is enabled without eagerfpu context
switching, one task's AVX state could become corrupted or leak
to other tasks. This is a bug and has bad security implications.

This only affects systems that have AVX/AVX2/AVX512 and this
issue will be found only when one actually uses AVX/AVX2/AVX512
_AND_ does eagerfpu=off.

Reference: Intel Software Developer's Manual Vol. 3A

Sec. 2.5 Control Registers:
TS Task Switched bit (bit 3 of CR0) -- Allows the saving of the
x87 FPU/ MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch
to be delayed until an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4
instruction is actually executed by the new task.

Sec. 13.4.1 Using the TS Flag to Control the Saving of the X87
FPU and SSE State
When the TS flag is set, the processor monitors the instruction
stream for x87 FPU, MMX, SSE instructions. When the processor
detects one of these instructions, it raises a
device-not-available exeception (#NM) prior to executing the
instruction.

Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/1452119094-7252-5-git-send-email-yu-cheng.yu@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/xstate.h | 11 ++++++-----
 arch/x86/kernel/fpu/init.c        |  6 ++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index 3a6c89b..af30fde 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -20,15 +20,16 @@
 
 /* Supported features which support lazy state saving */
 #define XFEATURE_MASK_LAZY	(XFEATURE_MASK_FP | \
-				 XFEATURE_MASK_SSE | \
+				 XFEATURE_MASK_SSE)
+
+/* Supported features which require eager state saving */
+#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | \
+				 XFEATURE_MASK_BNDCSR | \
 				 XFEATURE_MASK_YMM | \
-				 XFEATURE_MASK_OPMASK |	\
+				 XFEATURE_MASK_OPMASK | \
 				 XFEATURE_MASK_ZMM_Hi256 | \
 				 XFEATURE_MASK_Hi16_ZMM)
 
-/* Supported features which require eager state saving */
-#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)
-
 /* All currently supported features */
 #define XCNTXT_MASK	(XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
 
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index f0ab368..6d9f0a7 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -300,6 +300,12 @@ u64 __init fpu__get_supported_xfeatures_mask(void)
 static void __init fpu__clear_eager_fpu_features(void)
 {
 	setup_clear_cpu_cap(X86_FEATURE_MPX);
+	setup_clear_cpu_cap(X86_FEATURE_AVX);
+	setup_clear_cpu_cap(X86_FEATURE_AVX2);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512F);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512PF);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
+	setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
  2016-01-12 12:00   ` [tip:x86/asm] x86/fpu: Fix early FPU " tip-bot for yu-cheng yu
@ 2016-01-15 20:28     ` Borislav Petkov
  2016-01-15 20:50       ` Yu-cheng Yu
  0 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2016-01-15 20:28 UTC (permalink / raw)
  To: linux-kernel, peterz, torvalds, tglx, oleg, ravi.v.shankar,
	yu-cheng.yu, fenghua.yu, mingo, dave.hansen, quentin.casasnovas,
	bp, hpa, luto, sai.praneeth.prakhya
  Cc: linux-tip-commits

On Tue, Jan 12, 2016 at 04:00:49AM -0800, tip-bot for yu-cheng yu wrote:
> Commit-ID:  4f81cbafcce2c603db7865e9d0e461f7947d77d4
> Gitweb:     http://git.kernel.org/tip/4f81cbafcce2c603db7865e9d0e461f7947d77d4
> Author:     yu-cheng yu <yu-cheng.yu@intel.com>
> AuthorDate: Wed, 6 Jan 2016 14:24:51 -0800
> Committer:  Ingo Molnar <mingo@kernel.org>
> CommitDate: Tue, 12 Jan 2016 11:51:20 +0100
> 
> x86/fpu: Fix early FPU command-line parsing
> 
> The function fpu__init_system() is executed before
> parse_early_param(). This causes wrong FPU configuration. This
> patch fixes this issue by parsing boot_command_line in the
> beginning of fpu__init_system().
> 
> With all four patches in this series, each parameter disables
> features as the following:
> 
> eagerfpu=off: eagerfpu, avx, avx2, avx512, mpx
> no387: fpu
> nofxsr: fxsr, fxsropt, xmm
> noxsave: xsave, xsaveopt, xsaves, xsavec, avx, avx2, avx512,
> mpx, xgetbv1 noxsaveopt: xsaveopt
> noxsaves: xsaves
> 
> Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Fenghua Yu <fenghua.yu@intel.com>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
> Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: yu-cheng yu <yu-cheng.yu@intel.com>
> Link: http://lkml.kernel.org/r/1452119094-7252-2-git-send-email-yu-cheng.yu@intel.com
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
>  arch/x86/kernel/fpu/init.c | 109 ++++++++++++++++-----------------------------
> 1 file changed, 38 insertions(+), 71 deletions(-)

...

> + * We parse fpu parameters early because fpu__init_system() is executed
> + * before parse_early_param().
> + */
> +static void __init fpu__init_parse_early_param(void)
> +{
> +	/*
> +	 * No need to check "eagerfpu=auto" again, since it is the
> +	 * initial default.
> +	 */
> +	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
> +		eagerfpu = DISABLE;
> +	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
> +		eagerfpu = ENABLE;
> +
> +	if (cmdline_find_option_bool(boot_command_line, "no387"))
> +		setup_clear_cpu_cap(X86_FEATURE_FPU);
> +
> +	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> +		setup_clear_cpu_cap(X86_FEATURE_FXSR);
> +		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
> +		setup_clear_cpu_cap(X86_FEATURE_XMM);
> +	}
> +
> +	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
> +		fpu__xstate_clear_all_cpu_caps();
> +
> +	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
> +		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
> +
> +	if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
> +		setup_clear_cpu_cap(X86_FEATURE_XSAVES);

This could certainly be improved: we're iterating over the *whole*
command line each time for each option unconditionally instead of
iterating word by word and comparing it with all strings.

We'd need something like cmdline_for_each_word() or so, though...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
  2016-01-15 20:28     ` Borislav Petkov
@ 2016-01-15 20:50       ` Yu-cheng Yu
  2016-01-15 21:01         ` Dave Hansen
  0 siblings, 1 reply; 13+ messages in thread
From: Yu-cheng Yu @ 2016-01-15 20:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: linux-kernel, peterz, torvalds, tglx, oleg, ravi.v.shankar,
	fenghua.yu, mingo, dave.hansen, quentin.casasnovas, bp, hpa,
	luto, sai.praneeth.prakhya, linux-tip-commits

On Fri, Jan 15, 2016 at 09:28:58PM +0100, Borislav Petkov wrote:
> > +static void __init fpu__init_parse_early_param(void)
> > +{
> > +	/*
> > +	 * No need to check "eagerfpu=auto" again, since it is the
> > +	 * initial default.
> > +	 */
> > +	if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off"))
> > +		eagerfpu = DISABLE;
> > +	else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on"))
> > +		eagerfpu = ENABLE;
> > +
> > +	if (cmdline_find_option_bool(boot_command_line, "no387"))
> > +		setup_clear_cpu_cap(X86_FEATURE_FPU);
> > +
> > +	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> > +		setup_clear_cpu_cap(X86_FEATURE_FXSR);
> > +		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
> > +		setup_clear_cpu_cap(X86_FEATURE_XMM);
> > +	}
> > +
> > +	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
> > +		fpu__xstate_clear_all_cpu_caps();
> > +
> > +	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
> > +		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
> > +
> > +	if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
> > +		setup_clear_cpu_cap(X86_FEATURE_XSAVES);
> 
> This could certainly be improved: we're iterating over the *whole*
> command line each time for each option unconditionally instead of
> iterating word by word and comparing it with all strings.
> 
> We'd need something like cmdline_for_each_word() or so, though...
> 

That is a good point. I will work on it.

Thanks,
Yu-cheng

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
  2016-01-15 20:50       ` Yu-cheng Yu
@ 2016-01-15 21:01         ` Dave Hansen
  2016-01-15 21:09           ` Borislav Petkov
  0 siblings, 1 reply; 13+ messages in thread
From: Dave Hansen @ 2016-01-15 21:01 UTC (permalink / raw)
  To: Yu-cheng Yu, Borislav Petkov
  Cc: linux-kernel, peterz, torvalds, tglx, oleg, ravi.v.shankar,
	fenghua.yu, mingo, quentin.casasnovas, bp, hpa, luto,
	sai.praneeth.prakhya, linux-tip-commits

On 01/15/2016 12:50 PM, Yu-cheng Yu wrote:
>> > 
>> > This could certainly be improved: we're iterating over the *whole*
>> > command line each time for each option unconditionally instead of
>> > iterating word by word and comparing it with all strings.
>> > 
>> > We'd need something like cmdline_for_each_word() or so, though...
>> > 
> That is a good point. I will work on it.

I really don't think we need to do this.  It's code that runs *ONCE* at
boot time.  Let's not work on optimizing it unless we have some acute need.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [tip:x86/asm] x86/fpu: Fix early FPU command-line parsing
  2016-01-15 21:01         ` Dave Hansen
@ 2016-01-15 21:09           ` Borislav Petkov
  0 siblings, 0 replies; 13+ messages in thread
From: Borislav Petkov @ 2016-01-15 21:09 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Yu-cheng Yu, linux-kernel, peterz, torvalds, tglx, oleg,
	ravi.v.shankar, fenghua.yu, mingo, quentin.casasnovas, bp, hpa,
	luto, sai.praneeth.prakhya, linux-tip-commits

On Fri, Jan 15, 2016 at 01:01:37PM -0800, Dave Hansen wrote:
> I really don't think we need to do this. It's code that runs *ONCE* at
> boot time. Let's not work on optimizing it unless we have some acute
> need.

It was just a "it would be better if" suggestion, no one said anyone
should work on it. And sorry but if we can elegantly optimize something,
I think we should always do it.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-01-15 21:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-06 22:24 [PATCH 0/4] x86/fpu: FPU init code bugfixes yu-cheng yu
2016-01-06 22:24 ` [PATCH 1/4] x86/fpu: Fix early fpu command-line parsing yu-cheng yu
2016-01-12 12:00   ` [tip:x86/asm] x86/fpu: Fix early FPU " tip-bot for yu-cheng yu
2016-01-15 20:28     ` Borislav Petkov
2016-01-15 20:50       ` Yu-cheng Yu
2016-01-15 21:01         ` Dave Hansen
2016-01-15 21:09           ` Borislav Petkov
2016-01-06 22:24 ` [PATCH 2/4] x86/fpu: Disable XGETBV1 when no XSAVE yu-cheng yu
2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu
2016-01-06 22:24 ` [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off yu-cheng yu
2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu
2016-01-06 22:24 ` [PATCH 4/4] x86/fpu: Disable AVX " yu-cheng yu
2016-01-12 12:01   ` [tip:x86/asm] " tip-bot for yu-cheng yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).