From: "Fenghua Yu" <fenghua.yu@intel.com>
To: "H. Peter Anvin" <hpa@linux.intel.com>,
"Ingo Molnar" <mingo@elte.hu>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Asit K Mallick" <asit.k.mallick@intel.com>,
"Dave Hansen" <dave.hansen@intel.com>,
"Glenn Williamson" <glenn.p.williamson@intel.com>
Cc: "linux-kernel" <linux-kernel@vger.kernel.org>,
"x86" <x86@kernel.org>, "Fenghua Yu" <fenghua.yu@intel.com>
Subject: [PATCH Bugfix v2 1/4] x86/xsave.c: Fix xstate offsets and sizes enumeration
Date: Tue, 21 Apr 2015 21:51:56 -0700 [thread overview]
Message-ID: <1429678319-61356-2-git-send-email-fenghua.yu@intel.com> (raw)
In-Reply-To: <1429678319-61356-1-git-send-email-fenghua.yu@intel.com>
From: Fenghua Yu <fenghua.yu@intel.com>
When enumerating xstate offsets and sizes from cpuid (eax=0x0d, ecx>=2),
it's possible that state m is not implemented while state n (n>m)
is implemented. So enumeration shouldn't stop at state m.
There is no platform configured like above yet. But this could be a problem
in the future. For example, suppose XCR0=0xe7, that means FP, SSE, AVX, and
AVX-512 states are enabled and MPX states (bit 3 and 4) are not enabled.
Then in setup_xstate_features(), after finding BNDREGS size is 0 (i.e. eax
from CPUID xstate subleaf 3, break from the for loop. That stops finding
xstate_offsets and xstate_sizes for AVX-512. Later on incorrect
xstate_offsets and xstate_sizes for AVX-512 will be used in a few places
and will causes issues.
This patch enumerates xstate offsets and sizes for all kernel supported
xstates. If a state is not implemented in hardware or not enabled in XCR0,
its size is set as zero and its offset is read from cpuid.
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
---
arch/x86/kernel/xsave.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index 87a815b..3c0a9d1 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -465,23 +465,18 @@ static inline void xstate_enable(void)
*/
static void __init setup_xstate_features(void)
{
- int eax, ebx, ecx, edx, leaf = 0x2;
+ int eax, ebx, ecx, edx, leaf;
xstate_features = fls64(pcntxt_mask);
xstate_offsets = alloc_bootmem(xstate_features * sizeof(int));
xstate_sizes = alloc_bootmem(xstate_features * sizeof(int));
- do {
+ for (leaf = 2; leaf < xstate_features; leaf++) {
cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx);
- if (eax == 0)
- break;
-
xstate_offsets[leaf] = ebx;
xstate_sizes[leaf] = eax;
-
- leaf++;
- } while (1);
+ }
}
/*
--
1.8.1.2
next prev parent reply other threads:[~2015-04-22 4:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 4:51 [PATCH Bugfix v2 0/4] x86/xsave/xsaves: Fix a few xsave/xsaves related bugs Fenghua Yu
2015-04-22 4:51 ` Fenghua Yu [this message]
2015-04-22 4:51 ` [PATCH Bugfix v2 2/4] x86/xsaves: Define and use user_xstate_size for xstate size in signal context Fenghua Yu
2015-04-22 18:45 ` Dave Hansen
2015-04-22 19:05 ` Yu, Fenghua
2015-04-22 19:34 ` Dave Hansen
2015-04-23 0:06 ` Yu, Fenghua
2015-04-23 0:21 ` Dave Hansen
2015-04-23 0:23 ` Yu, Fenghua
2015-04-23 0:34 ` Dave Hansen
2015-04-23 17:09 ` Yu, Fenghua
2015-04-23 21:32 ` Dave Hansen
2015-04-28 14:28 ` Dave Hansen
2015-04-28 22:09 ` Dave Hansen
2015-04-28 22:11 ` Yu, Fenghua
2015-04-29 13:53 ` Dave Hansen
2015-04-22 4:51 ` [PATCH Bugfix v2 3/4] x86/xsaves: Rename xstate_size to kernel_xstate_size to explicitly distinguish xstate size in kernel from user space Fenghua Yu
2015-04-22 4:51 ` [PATCH Bugfix v2 4/4] x86/xsave: Don't add new states in xsave_struct Fenghua 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=1429678319-61356-2-git-send-email-fenghua.yu@intel.com \
--to=fenghua.yu@intel.com \
--cc=asit.k.mallick@intel.com \
--cc=dave.hansen@intel.com \
--cc=glenn.p.williamson@intel.com \
--cc=hpa@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--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