From: yu-cheng yu <yu-cheng.yu@intel.com>
To: linux-kernel@vger.kernel.org
Cc: yu-cheng yu <yu-cheng.yu@intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@suse.de>,
Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
"Ravi V. Shankar" <ravi.v.shankar@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>
Subject: [PATCH 3/4] x86/fpu: Disable MPX when eagerfpu is off
Date: Wed, 6 Jan 2016 14:24:53 -0800 [thread overview]
Message-ID: <1452119094-7252-4-git-send-email-yu-cheng.yu@intel.com> (raw)
In-Reply-To: <1452119094-7252-1-git-send-email-yu-cheng.yu@intel.com>
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
next prev parent reply other threads:[~2016-01-06 22:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` yu-cheng yu [this message]
2016-01-12 12:01 ` [tip:x86/asm] x86/fpu: Disable MPX when eagerfpu is off 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452119094-7252-4-git-send-email-yu-cheng.yu@intel.com \
--to=yu-cheng.yu@intel.com \
--cc=bp@suse.de \
--cc=dave.hansen@linux.intel.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=ravi.v.shankar@intel.com \
--cc=sai.praneeth.prakhya@intel.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome