diff options
author | Dave Hansen <dave.hansen@linux.intel.com> | 2015-09-02 19:31:31 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-09-14 06:22:02 -0400 |
commit | ef78f2a4bf84d8db9f36868decca2dc24e02a6af (patch) | |
tree | 42fa0670920bba069749cef56d1b5b239fcc8fad /arch/x86/kernel | |
parent | e6e888f96b4a531886f3bf29ba9af0b6f1026365 (diff) |
x86/fpu: Check CPU-provided sizes against struct declarations
We now have C structures defined for each of the XSAVE state
components that we support. This patch adds checks during our
verification pass to ensure that the CPU-provided data
enumerated in CPUID leaves matches our C structures.
If not, we warn and dump all the XSAVE CPUID leaves.
Note: this *actually* found an inconsistency with the MPX
'bndcsr' state. The hardware pads it out differently from
our C structures. This patch caught it and warned.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: dave@sr71.net
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20150902233131.A8DB36DA@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r-- | arch/x86/kernel/fpu/xstate.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index a8297f2ca2d1..6454f2731b56 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c | |||
@@ -432,6 +432,49 @@ static void __xstate_dump_leaves(void) | |||
432 | } \ | 432 | } \ |
433 | } while (0) | 433 | } while (0) |
434 | 434 | ||
435 | #define XCHECK_SZ(sz, nr, nr_macro, __struct) do { \ | ||
436 | if ((nr == nr_macro) && \ | ||
437 | WARN_ONCE(sz != sizeof(__struct), \ | ||
438 | "%s: struct is %zu bytes, cpu state %d bytes\n", \ | ||
439 | __stringify(nr_macro), sizeof(__struct), sz)) { \ | ||
440 | __xstate_dump_leaves(); \ | ||
441 | } \ | ||
442 | } while (0) | ||
443 | |||
444 | /* | ||
445 | * We have a C struct for each 'xstate'. We need to ensure | ||
446 | * that our software representation matches what the CPU | ||
447 | * tells us about the state's size. | ||
448 | */ | ||
449 | static void check_xstate_against_struct(int nr) | ||
450 | { | ||
451 | /* | ||
452 | * Ask the CPU for the size of the state. | ||
453 | */ | ||
454 | int sz = xfeature_size(nr); | ||
455 | /* | ||
456 | * Match each CPU state with the corresponding software | ||
457 | * structure. | ||
458 | */ | ||
459 | XCHECK_SZ(sz, nr, XFEATURE_YMM, struct ymmh_struct); | ||
460 | XCHECK_SZ(sz, nr, XFEATURE_BNDREGS, struct mpx_bndreg_state); | ||
461 | XCHECK_SZ(sz, nr, XFEATURE_BNDCSR, struct mpx_bndcsr_state); | ||
462 | XCHECK_SZ(sz, nr, XFEATURE_OPMASK, struct avx_512_opmask_state); | ||
463 | XCHECK_SZ(sz, nr, XFEATURE_ZMM_Hi256, struct avx_512_zmm_uppers_state); | ||
464 | XCHECK_SZ(sz, nr, XFEATURE_Hi16_ZMM, struct avx_512_hi16_state); | ||
465 | |||
466 | /* | ||
467 | * Make *SURE* to add any feature numbers in below if | ||
468 | * there are "holes" in the xsave state component | ||
469 | * numbers. | ||
470 | */ | ||
471 | if ((nr < XFEATURE_YMM) || | ||
472 | (nr >= XFEATURE_MAX)) { | ||
473 | WARN_ONCE(1, "no structure for xstate: %d\n", nr); | ||
474 | XSTATE_WARN_ON(1); | ||
475 | } | ||
476 | } | ||
477 | |||
435 | /* | 478 | /* |
436 | * This essentially double-checks what the cpu told us about | 479 | * This essentially double-checks what the cpu told us about |
437 | * how large the XSAVE buffer needs to be. We are recalculating | 480 | * how large the XSAVE buffer needs to be. We are recalculating |
@@ -445,6 +488,8 @@ static void do_extra_xstate_size_checks(void) | |||
445 | for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { | 488 | for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { |
446 | if (!xfeature_enabled(i)) | 489 | if (!xfeature_enabled(i)) |
447 | continue; | 490 | continue; |
491 | |||
492 | check_xstate_against_struct(i); | ||
448 | /* | 493 | /* |
449 | * Supervisor state components can be managed only by | 494 | * Supervisor state components can be managed only by |
450 | * XSAVES, which is compacted-format only. | 495 | * XSAVES, which is compacted-format only. |