The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] x86/fpu: Fix nofxsr regression
@ 2019-07-02 21:39 Andi Kleen
  2019-07-02 22:17 ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2019-07-02 21:39 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Andi Kleen, Vegard Nossum,
	Sebastian Andrzej Siewior

From: Andi Kleen <ak@linux.intel.com>

Vegard Nossum reports:

The commit for this patch in mainline
(ccb18db2ab9d ("x86/fpu: Make XSAVE check ...")) causes the kernel to hang on
boot when passing the "nofxsr" option:

$ kvm -cpu host -kernel arch/x86/boot/bzImage -append "console=ttyS0 nofxsr
earlyprintk=ttyS0" -serial stdio -display none -smp 2
early console in extract_kernel
input_data: 0x0000000001dea276
input_len: 0x0000000000500704
output: 0x0000000001000000
output_len: 0x00000000012c79b4
kernel_total_size: 0x0000000000f24000
booted via startup_32()
Physical KASLR using RDRAND RDTSC...
Virtual KASLR using RDRAND RDTSC...

Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting the kernel.
[..hang..]

<<<

Sebastian Siewior did the following analysis:

as a result of nofxsr we do:
[0]     setup_clear_cpu_cap(X86_FEATURE_FXSR);
[1]     setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
[2]     setup_clear_cpu_cap(X86_FEATURE_XMM);

the commit in question removes then XFEATURE_MASK_SSE from
`xfeatures_mask'.
Boot stops in fpu__init_cpu_xstate() / xsetbv() due to #GP:
|If an attempt is made to set XCR0[2:1] to 10b.
(from Vol. 2C).

[1] is "harmless". Dropping [2] does not fix the issue because [0]
still clears all three flags due to
| static const struct cpuid_dep cpuid_deps[] = {
…
|      { X86_FEATURE_XMM,              X86_FEATURE_FXSR      },

Clearing additionally XMM2 (and adding the missing bits to
xsave_cpuid_features/xfeature_names) would boot further.
Later it crashes in raid6 while probing for AVX/2 code…

Disabling XMM+XMM2 in order get (and fixing it up for AVX+AVX2) would
give use XSAVE instead of FSAVE.
This won't work on 64bit userland because it expects SSE to be around
(and FXSR to save the SSE bits).
Even my 32bit Debian Wheezy doesn't work because it wants FXSR :)

So if it is unlikely to have XSAVE but no FXSR I would suggest to add
"fpu__xstate_clear_all_cpu_caps()" to nofxsr and behave like "nofxsr
noxsave".

<<<

Also nofxsr is useless on 64bit kernels because 64bit user space
always uses SSE2, and without FXSR there is no SSE support.

This patch:
- Makes nofxsr 32bit only
It was already documented to be 32bit only, but not implemented this
way.

- Implements Sebastian's suggestion of calling
fpu__xstate_clear_all_cpu_caps() for nofxsr to clear all depending
bits.

With this a 32bit kernel boots on qemu with nofxsr upto user space
crashing (I don't have a 32bit image that doesn't need SSE2),
and a 64bit kernel also fully boots with nofxsr (by ignoring
the option)

Fixes: ccb18db2ab9d ("x86/fpu: Make XSAVE check ...)
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Suggested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/kernel/fpu/init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index ef0030e3fe6b..81c730af7454 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -255,7 +255,9 @@ static void __init fpu__init_parse_early_param(void)
 	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")) {
+	if (!IS_ENABLED(CONFIG_64BIT) &&
+		cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+		fpu__xstate_clear_all_cpu_caps();
 		setup_clear_cpu_cap(X86_FEATURE_FXSR);
 		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
 		setup_clear_cpu_cap(X86_FEATURE_XMM);
-- 
2.20.1


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

* Re: [PATCH] x86/fpu: Fix nofxsr regression
  2019-07-02 21:39 [PATCH] x86/fpu: Fix nofxsr regression Andi Kleen
@ 2019-07-02 22:17 ` Thomas Gleixner
  2019-07-03  7:24   ` Sebastian Andrzej Siewior
  2019-07-03  8:32   ` [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs Sebastian Andrzej Siewior
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Gleixner @ 2019-07-02 22:17 UTC (permalink / raw)
  To: Andi Kleen
  Cc: x86, linux-kernel, Andi Kleen, Vegard Nossum,
	Sebastian Andrzej Siewior

On Tue, 2 Jul 2019, Andi Kleen wrote:
>  
> -	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> +	if (!IS_ENABLED(CONFIG_64BIT) &&
> +		cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> +		fpu__xstate_clear_all_cpu_caps();
>  		setup_clear_cpu_cap(X86_FEATURE_FXSR);
>  		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
>  		setup_clear_cpu_cap(X86_FEATURE_XMM);

This is a mixture of disabling features explicitely and having the
dependencies in cpuid-deps. Even 2 of the existing ones are pointless
because clear(FXSR) already clears the other two.

Why not make XSAVE depend on XMM or whatever is the right dependency?

Thanks,

	tglx

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

* Re: [PATCH] x86/fpu: Fix nofxsr regression
  2019-07-02 22:17 ` Thomas Gleixner
@ 2019-07-03  7:24   ` Sebastian Andrzej Siewior
  2019-07-03  8:32   ` [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs Sebastian Andrzej Siewior
  1 sibling, 0 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-07-03  7:24 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen, Vegard Nossum

On 2019-07-03 00:17:17 [+0200], Thomas Gleixner wrote:
> On Tue, 2 Jul 2019, Andi Kleen wrote:
> >  
> > -	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> > +	if (!IS_ENABLED(CONFIG_64BIT) &&
> > +		cmdline_find_option_bool(boot_command_line, "nofxsr")) {
> > +		fpu__xstate_clear_all_cpu_caps();
> >  		setup_clear_cpu_cap(X86_FEATURE_FXSR);
> >  		setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
> >  		setup_clear_cpu_cap(X86_FEATURE_XMM);
> 
> This is a mixture of disabling features explicitely and having the
> dependencies in cpuid-deps. Even 2 of the existing ones are pointless
> because clear(FXSR) already clears the other two.
> 
> Why not make XSAVE depend on XMM or whatever is the right dependency?

I have something half way done.

> Thanks,
> 
> 	tglx

Sebastian

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

* [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs
  2019-07-02 22:17 ` Thomas Gleixner
  2019-07-03  7:24   ` Sebastian Andrzej Siewior
@ 2019-07-03  8:32   ` Sebastian Andrzej Siewior
  2019-07-04  6:07     ` [PATCH] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps() Sebastian Andrzej Siewior
  2019-07-07 10:07     ` [tip:x86/fpu] x86/fpu: Make 'no387' and 'nofxsr' command line options useful tip-bot for Sebastian Andrzej Siewior
  1 sibling, 2 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-07-03  8:32 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen, Vegard Nossum

The command line option `no387' is designed to disable the FPU entirely.
The documentation says to disable the coprocessor and the Kconfig entry
for MATH_EMULATION says to set it in order to use emulation. It should
be restricted to 32bit only because 64bit expect SSE (which includes
basic FPU and there is not emulation for SSE).

The command line option `nofxsr' should also be limited to 32bit because
FXSR is part of the required flags on 64bit so turning it off is not
possible.

Clearing X86_FEATURE_FPU without emulation enabled will not work anyway
and hang in fpu__init_system_early_generic() before console is enabled.

Setting additioal dependencies, ensures that the CPU still boots on a
modern CPU. Otherwise, dropping FPU will leave FXSR enabled causing the
kernel to crash early in fpu__init_system_mxcsr().
With XSAVE support it will crash in fpu__init_cpu_xstate(). The problem
is that xsetbv() with YMM set and SSE cleared is not allowed.  That
means XSAVE has to be disabled. The XSAVE support is disabled in
fpu__init_system_xstate_size_legacy() but it is too late. It can be
removed, it has been added in commit

  1f999ab5a1360 ("x86, xsave: Disable xsave in i387 emulation mode")

to use `no387' on a CPU with XSAVE support.

All this happens before console output.
After hat, the next possible crash is in RAID6 detect code because MMX
remained enabled. With a 3DNOW enabled config it will explode in
memcpy() for instance due to kernel_fpu_begin() but this is
unconditionally enabled.

This is enough to boot a Debian Wheezy on a 32bit qemu "host" CPU which
supports everything up to XSAVES, AVX2 without 3DNOW. Later, Debian
increased the minimum requirements to i686 which means it does not boot
userland atleast due to CMOV.

After masking the additional features it still keeps SSE4A and 3DNOW*
enabled (if present on the host) but those are unused in the kernel.

Restrict `no387' and `nofxsr' otions to 32bit only. Add dependencies for
FPU, FXSR to additionaly mask CMOV, MMX, XSAVE if FXSR or FPU is cleared.

Link: https://lkml.kernel.org/r/20190701121710.vardxktdc63gtcj5@linutronix.de>
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/kernel/cpu/cpuid-deps.c |  5 +++++
 arch/x86/kernel/fpu/init.c       | 17 +++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 2c0bd38a44ab1..e794e3860fc83 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -20,6 +20,7 @@ struct cpuid_dep {
  * but it's difficult to tell that to the init reference checker.
  */
 static const struct cpuid_dep cpuid_deps[] = {
+	{ X86_FEATURE_FXSR,		X86_FEATURE_FPU	      },
 	{ X86_FEATURE_XSAVEOPT,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XSAVEC,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XSAVES,		X86_FEATURE_XSAVE     },
@@ -27,7 +28,11 @@ static const struct cpuid_dep cpuid_deps[] = {
 	{ X86_FEATURE_PKU,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_MPX,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XGETBV1,		X86_FEATURE_XSAVE     },
+	{ X86_FEATURE_CMOV,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_MMX,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_MMXEXT,		X86_FEATURE_MMX       },
 	{ X86_FEATURE_FXSR_OPT,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_XSAVE,		X86_FEATURE_FXSR      },
 	{ X86_FEATURE_XMM,		X86_FEATURE_FXSR      },
 	{ X86_FEATURE_XMM2,		X86_FEATURE_XMM       },
 	{ X86_FEATURE_XMM3,		X86_FEATURE_XMM2      },
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index ef0030e3fe6b9..5baae74af4f91 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -204,12 +204,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
 	 */
 
 	if (!boot_cpu_has(X86_FEATURE_FPU)) {
-		/*
-		 * Disable xsave as we do not support it if i387
-		 * emulation is enabled.
-		 */
-		setup_clear_cpu_cap(X86_FEATURE_XSAVE);
-		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
 		fpu_kernel_xstate_size = sizeof(struct swregs_state);
 	} else {
 		if (boot_cpu_has(X86_FEATURE_FXSR))
@@ -252,14 +246,17 @@ static void __init fpu__init_parse_early_param(void)
 	char *argptr = arg;
 	int bit;
 
+#ifdef CONFIG_X86_32
 	if (cmdline_find_option_bool(boot_command_line, "no387"))
+#ifdef CONFIG_MATH_EMULATION
 		setup_clear_cpu_cap(X86_FEATURE_FPU);
+#else
+		pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n");
+#endif
 
-	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+	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);
-	}
+#endif
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
 		fpu__xstate_clear_all_cpu_caps();
-- 
2.20.1


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

* [PATCH] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps()
  2019-07-03  8:32   ` [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs Sebastian Andrzej Siewior
@ 2019-07-04  6:07     ` Sebastian Andrzej Siewior
  2019-07-07 10:07       ` [tip:x86/fpu] " tip-bot for Sebastian Andrzej Siewior
  2019-07-07 10:07     ` [tip:x86/fpu] x86/fpu: Make 'no387' and 'nofxsr' command line options useful tip-bot for Sebastian Andrzej Siewior
  1 sibling, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-07-04  6:07 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andi Kleen, x86, linux-kernel, Andi Kleen, Vegard Nossum

All fpu__xstate_clear_all_cpu_caps() does is to invoke one simple
function since commit

  73e3a7d2a7c3b ("x86/fpu: Remove the explicit clearing of XSAVE dependent features")

so it will be better to simply invoke that function directly.

Inline fpu__xstate_clear_all_cpu_caps().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/include/asm/fpu/xstate.h |  1 -
 arch/x86/kernel/fpu/init.c        |  2 +-
 arch/x86/kernel/fpu/xstate.c      | 11 +----------
 3 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index 7e42b285c8562..c6136d79f8c07 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -47,7 +47,6 @@ extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
 extern void __init update_regset_xstate_info(unsigned int size,
 					     u64 xstate_mask);
 
-void fpu__xstate_clear_all_cpu_caps(void);
 void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
 const void *get_xsave_field_ptr(int xfeature_nr);
 int using_compacted_format(void);
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 5baae74af4f91..6ce7e0a23268f 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -259,7 +259,7 @@ static void __init fpu__init_parse_early_param(void)
 #endif
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
-		fpu__xstate_clear_all_cpu_caps();
+		setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
 		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 3c36dd1784db6..7b4c52aa929fb 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -67,15 +67,6 @@ static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
  */
 unsigned int fpu_user_xstate_size;
 
-/*
- * Clear all of the X86_FEATURE_* bits that are unavailable
- * when the CPU has no XSAVE support.
- */
-void fpu__xstate_clear_all_cpu_caps(void)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
-}
-
 /*
  * Return whether the system supports a given xfeature.
  *
@@ -709,7 +700,7 @@ static void fpu__init_disable_system_xstate(void)
 {
 	xfeatures_mask = 0;
 	cr4_clear_bits(X86_CR4_OSXSAVE);
-	fpu__xstate_clear_all_cpu_caps();
+	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 }
 
 /*
-- 
2.20.1


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

* [tip:x86/fpu] x86/fpu: Make 'no387' and 'nofxsr' command line options useful
  2019-07-03  8:32   ` [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs Sebastian Andrzej Siewior
  2019-07-04  6:07     ` [PATCH] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps() Sebastian Andrzej Siewior
@ 2019-07-07 10:07     ` tip-bot for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2019-07-07 10:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, bigeasy, vegard.nossum, tglx, mingo, hpa

Commit-ID:  9838e3bff0f92f23fcd50fe1ff1d4b3e91b8a448
Gitweb:     https://git.kernel.org/tip/9838e3bff0f92f23fcd50fe1ff1d4b3e91b8a448
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Wed, 3 Jul 2019 10:32:47 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 7 Jul 2019 12:01:46 +0200

x86/fpu: Make 'no387' and 'nofxsr' command line options useful

The command line option `no387' is designed to disable the FPU
entirely. This only 'works' with CONFIG_MATH_EMULATION enabled.

But on 64bit this cannot work because user space expects SSE to work which
required basic FPU support. MATH_EMULATION does not help because SSE is not
emulated.

The command line option `nofxsr' should also be limited to 32bit because
FXSR is part of the required flags on 64bit so turning it off is not
possible.

Clearing X86_FEATURE_FPU without emulation enabled will not work anyway and
hang in fpu__init_system_early_generic() before the console is enabled.

Setting additioal dependencies, ensures that the CPU still boots on a
modern CPU. Otherwise, dropping FPU will leave FXSR enabled causing the
kernel to crash early in fpu__init_system_mxcsr().

With XSAVE support it will crash in fpu__init_cpu_xstate(). The problem is
that xsetbv() with XMM set and SSE cleared is not allowed.  That means
XSAVE has to be disabled. The XSAVE support is disabled in
fpu__init_system_xstate_size_legacy() but it is too late. It can be
removed, it has been added in commit

  1f999ab5a1360 ("x86, xsave: Disable xsave in i387 emulation mode")

to use `no387' on a CPU with XSAVE support.

All this happens before console output.

After hat, the next possible crash is in RAID6 detect code because MMX
remained enabled. With a 3DNOW enabled config it will explode in memcpy()
for instance due to kernel_fpu_begin() but this is unconditionally enabled.

This is enough to boot a Debian Wheezy on a 32bit qemu "host" CPU which
supports everything up to XSAVES, AVX2 without 3DNOW. Later, Debian
increased the minimum requirements to i686 which means it does not boot
userland atleast due to CMOV.

After masking the additional features it still keeps SSE4A and 3DNOW*
enabled (if present on the host) but those are unused in the kernel.

Restrict `no387' and `nofxsr' otions to 32bit only. Add dependencies for
FPU, FXSR to additionaly mask CMOV, MMX, XSAVE if FXSR or FPU is cleared.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190703083247.57kjrmlxkai3vpw3@linutronix.de

---
 arch/x86/kernel/cpu/cpuid-deps.c |  5 +++++
 arch/x86/kernel/fpu/init.c       | 17 +++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 2c0bd38a44ab..e794e3860fc8 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -20,6 +20,7 @@ struct cpuid_dep {
  * but it's difficult to tell that to the init reference checker.
  */
 static const struct cpuid_dep cpuid_deps[] = {
+	{ X86_FEATURE_FXSR,		X86_FEATURE_FPU	      },
 	{ X86_FEATURE_XSAVEOPT,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XSAVEC,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XSAVES,		X86_FEATURE_XSAVE     },
@@ -27,7 +28,11 @@ static const struct cpuid_dep cpuid_deps[] = {
 	{ X86_FEATURE_PKU,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_MPX,		X86_FEATURE_XSAVE     },
 	{ X86_FEATURE_XGETBV1,		X86_FEATURE_XSAVE     },
+	{ X86_FEATURE_CMOV,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_MMX,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_MMXEXT,		X86_FEATURE_MMX       },
 	{ X86_FEATURE_FXSR_OPT,		X86_FEATURE_FXSR      },
+	{ X86_FEATURE_XSAVE,		X86_FEATURE_FXSR      },
 	{ X86_FEATURE_XMM,		X86_FEATURE_FXSR      },
 	{ X86_FEATURE_XMM2,		X86_FEATURE_XMM       },
 	{ X86_FEATURE_XMM3,		X86_FEATURE_XMM2      },
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index ef0030e3fe6b..5baae74af4f9 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -204,12 +204,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
 	 */
 
 	if (!boot_cpu_has(X86_FEATURE_FPU)) {
-		/*
-		 * Disable xsave as we do not support it if i387
-		 * emulation is enabled.
-		 */
-		setup_clear_cpu_cap(X86_FEATURE_XSAVE);
-		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
 		fpu_kernel_xstate_size = sizeof(struct swregs_state);
 	} else {
 		if (boot_cpu_has(X86_FEATURE_FXSR))
@@ -252,14 +246,17 @@ static void __init fpu__init_parse_early_param(void)
 	char *argptr = arg;
 	int bit;
 
+#ifdef CONFIG_X86_32
 	if (cmdline_find_option_bool(boot_command_line, "no387"))
+#ifdef CONFIG_MATH_EMULATION
 		setup_clear_cpu_cap(X86_FEATURE_FPU);
+#else
+		pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n");
+#endif
 
-	if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+	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);
-	}
+#endif
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
 		fpu__xstate_clear_all_cpu_caps();

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

* [tip:x86/fpu] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps()
  2019-07-04  6:07     ` [PATCH] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps() Sebastian Andrzej Siewior
@ 2019-07-07 10:07       ` tip-bot for Sebastian Andrzej Siewior
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2019-07-07 10:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, bigeasy, mingo, linux-kernel, tglx

Commit-ID:  7891bc0ab739a31538b5f879a523232b8b07a0d3
Gitweb:     https://git.kernel.org/tip/7891bc0ab739a31538b5f879a523232b8b07a0d3
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Thu, 4 Jul 2019 08:07:43 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 7 Jul 2019 12:01:47 +0200

x86/fpu: Inline fpu__xstate_clear_all_cpu_caps()

All fpu__xstate_clear_all_cpu_caps() does is to invoke one simple
function since commit

  73e3a7d2a7c3b ("x86/fpu: Remove the explicit clearing of XSAVE dependent features")

so invoke that function directly and remove the wrapper.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190704060743.rvew4yrjd6n33uzx@linutronix.de

---
 arch/x86/include/asm/fpu/xstate.h |  1 -
 arch/x86/kernel/fpu/init.c        |  2 +-
 arch/x86/kernel/fpu/xstate.c      | 11 +----------
 3 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index 7e42b285c856..c6136d79f8c0 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -47,7 +47,6 @@ extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
 extern void __init update_regset_xstate_info(unsigned int size,
 					     u64 xstate_mask);
 
-void fpu__xstate_clear_all_cpu_caps(void);
 void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
 const void *get_xsave_field_ptr(int xfeature_nr);
 int using_compacted_format(void);
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 5baae74af4f9..6ce7e0a23268 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -259,7 +259,7 @@ static void __init fpu__init_parse_early_param(void)
 #endif
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsave"))
-		fpu__xstate_clear_all_cpu_caps();
+		setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 
 	if (cmdline_find_option_bool(boot_command_line, "noxsaveopt"))
 		setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 3c36dd1784db..7b4c52aa929f 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -67,15 +67,6 @@ static unsigned int xstate_comp_offsets[sizeof(xfeatures_mask)*8];
  */
 unsigned int fpu_user_xstate_size;
 
-/*
- * Clear all of the X86_FEATURE_* bits that are unavailable
- * when the CPU has no XSAVE support.
- */
-void fpu__xstate_clear_all_cpu_caps(void)
-{
-	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
-}
-
 /*
  * Return whether the system supports a given xfeature.
  *
@@ -709,7 +700,7 @@ static void fpu__init_disable_system_xstate(void)
 {
 	xfeatures_mask = 0;
 	cr4_clear_bits(X86_CR4_OSXSAVE);
-	fpu__xstate_clear_all_cpu_caps();
+	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 }
 
 /*

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

end of thread, other threads:[~2019-07-07 10:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-02 21:39 [PATCH] x86/fpu: Fix nofxsr regression Andi Kleen
2019-07-02 22:17 ` Thomas Gleixner
2019-07-03  7:24   ` Sebastian Andrzej Siewior
2019-07-03  8:32   ` [PATCH] x86/fpu: Make no387 and nofxsr work a little better on modern CPUs Sebastian Andrzej Siewior
2019-07-04  6:07     ` [PATCH] x86/fpu: Inline fpu__xstate_clear_all_cpu_caps() Sebastian Andrzej Siewior
2019-07-07 10:07       ` [tip:x86/fpu] " tip-bot for Sebastian Andrzej Siewior
2019-07-07 10:07     ` [tip:x86/fpu] x86/fpu: Make 'no387' and 'nofxsr' command line options useful tip-bot for Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox