aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel
diff options
context:
space:
mode:
authorYu-cheng Yu <yu-cheng.yu@intel.com>2016-06-17 16:07:15 -0400
committerIngo Molnar <mingo@kernel.org>2016-07-10 11:12:10 -0400
commit03482e08a87d24e5c8c23e6981c482e832cf3bdc (patch)
tree89f2f7030958e81056b8635f737d213f8aeb7883 /arch/x86/kernel
parent08fb98f5bf95cef902fc30427b39617a6f6875c7 (diff)
x86/fpu/xstate: Align xstate components according to CPUID
CPUID function 0x0d, sub function (i, i > 1) returns in ecx[1] the alignment requirement of component 'i' when the compacted format is used. If ecx[1] is 0, component 'i' is located immediately following the preceding component. If ecx[1] is 1, component 'i' is located on the next 64-byte boundary following the preceding component. Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> Reviewed-by: Dave Hansen <dave.hansen@intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.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> Link: http://lkml.kernel.org/r/331e2bef1a0a7a584f06adde095b6bbfbe166472.1466179491.git.yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r--arch/x86/kernel/fpu/xstate.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 0b01f003df8b..7963029cb4ad 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -270,6 +270,33 @@ static void __init print_xstate_features(void)
270} 270}
271 271
272/* 272/*
273 * This check is important because it is easy to get XSTATE_*
274 * confused with XSTATE_BIT_*.
275 */
276#define CHECK_XFEATURE(nr) do { \
277 WARN_ON(nr < FIRST_EXTENDED_XFEATURE); \
278 WARN_ON(nr >= XFEATURE_MAX); \
279} while (0)
280
281/*
282 * We could cache this like xstate_size[], but we only use
283 * it here, so it would be a waste of space.
284 */
285static int xfeature_is_aligned(int xfeature_nr)
286{
287 u32 eax, ebx, ecx, edx;
288
289 CHECK_XFEATURE(xfeature_nr);
290 cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx);
291 /*
292 * The value returned by ECX[1] indicates the alignment
293 * of state component 'i' when the compacted format
294 * of the extended region of an XSAVE area is used:
295 */
296 return !!(ecx & 2);
297}
298
299/*
273 * This function sets up offsets and sizes of all extended states in 300 * This function sets up offsets and sizes of all extended states in
274 * xsave area. This supports both standard format and compacted format 301 * xsave area. This supports both standard format and compacted format
275 * of the xsave aread. 302 * of the xsave aread.
@@ -306,10 +333,14 @@ static void __init setup_xstate_comp(void)
306 else 333 else
307 xstate_comp_sizes[i] = 0; 334 xstate_comp_sizes[i] = 0;
308 335
309 if (i > FIRST_EXTENDED_XFEATURE) 336 if (i > FIRST_EXTENDED_XFEATURE) {
310 xstate_comp_offsets[i] = xstate_comp_offsets[i-1] 337 xstate_comp_offsets[i] = xstate_comp_offsets[i-1]
311 + xstate_comp_sizes[i-1]; 338 + xstate_comp_sizes[i-1];
312 339
340 if (xfeature_is_aligned(i))
341 xstate_comp_offsets[i] =
342 ALIGN(xstate_comp_offsets[i], 64);
343 }
313 } 344 }
314} 345}
315 346
@@ -366,33 +397,6 @@ static int xfeature_is_user(int xfeature_nr)
366} 397}
367*/ 398*/
368 399
369/*
370 * This check is important because it is easy to get XSTATE_*
371 * confused with XSTATE_BIT_*.
372 */
373#define CHECK_XFEATURE(nr) do { \
374 WARN_ON(nr < FIRST_EXTENDED_XFEATURE); \
375 WARN_ON(nr >= XFEATURE_MAX); \
376} while (0)
377
378/*
379 * We could cache this like xstate_size[], but we only use
380 * it here, so it would be a waste of space.
381 */
382static int xfeature_is_aligned(int xfeature_nr)
383{
384 u32 eax, ebx, ecx, edx;
385
386 CHECK_XFEATURE(xfeature_nr);
387 cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx);
388 /*
389 * The value returned by ECX[1] indicates the alignment
390 * of state component i when the compacted format
391 * of the extended region of an XSAVE area is used
392 */
393 return !!(ecx & 2);
394}
395
396static int xfeature_uncompacted_offset(int xfeature_nr) 400static int xfeature_uncompacted_offset(int xfeature_nr)
397{ 401{
398 u32 eax, ebx, ecx, edx; 402 u32 eax, ebx, ecx, edx;