diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2010-07-21 17:23:10 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2010-07-21 18:33:54 -0400 |
commit | 1cff92d8fdb27684308864d9cdb324bee43b40ab (patch) | |
tree | 65a6060dab843f5f2e32a8e0fce0200eeb9d44ef | |
parent | 4995b9dba908436c1611454f9bd2cb3ddf6babee (diff) |
x86, xsave: Make xstate_enable_boot_cpu() __init, protect on CPU 0
xstate_enable_boot_cpu() is, as the name implies, only used on the
boot CPU; furthermore, it invokes alloc_bootmem(), which is __init;
hence it needs to be tagged __init rather than __cpuinit.
Furthermore, it is *not* safe in the long run to rely on CPU 0 only
coming online during the early boot -- at some point we're going to
support offlining (and re-onlining) the boot CPU, and at that point we
must not call xstate_enable_boot_cpu() again.
The code is a fair bit more obscure than one would like, because the
__ref overrides aren't quite powerful enough.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Acked-by: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Robert Richter <robert.richter@amd.com>
LKML-Reference: <4C476236.1020302@zytor.com>
-rw-r--r-- | arch/x86/kernel/xsave.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c index cfc7901ee94e..b2549c3eb2c3 100644 --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c | |||
@@ -360,10 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate); | |||
360 | /* | 360 | /* |
361 | * Enable the extended processor state save/restore feature | 361 | * Enable the extended processor state save/restore feature |
362 | */ | 362 | */ |
363 | static inline void xstate_enable(u64 mask) | 363 | static inline void xstate_enable(void) |
364 | { | 364 | { |
365 | set_in_cr4(X86_CR4_OSXSAVE); | 365 | set_in_cr4(X86_CR4_OSXSAVE); |
366 | xsetbv(XCR_XFEATURE_ENABLED_MASK, mask); | 366 | xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask); |
367 | } | 367 | } |
368 | 368 | ||
369 | /* | 369 | /* |
@@ -421,7 +421,7 @@ static void __init setup_xstate_init(void) | |||
421 | /* | 421 | /* |
422 | * Enable and initialize the xsave feature. | 422 | * Enable and initialize the xsave feature. |
423 | */ | 423 | */ |
424 | static void __cpuinit xstate_enable_boot_cpu(void) | 424 | static void __init xstate_enable_boot_cpu(void) |
425 | { | 425 | { |
426 | unsigned int eax, ebx, ecx, edx; | 426 | unsigned int eax, ebx, ecx, edx; |
427 | 427 | ||
@@ -444,7 +444,7 @@ static void __cpuinit xstate_enable_boot_cpu(void) | |||
444 | */ | 444 | */ |
445 | pcntxt_mask = pcntxt_mask & XCNTXT_MASK; | 445 | pcntxt_mask = pcntxt_mask & XCNTXT_MASK; |
446 | 446 | ||
447 | xstate_enable(pcntxt_mask); | 447 | xstate_enable(); |
448 | 448 | ||
449 | /* | 449 | /* |
450 | * Recompute the context size for enabled features | 450 | * Recompute the context size for enabled features |
@@ -462,16 +462,22 @@ static void __cpuinit xstate_enable_boot_cpu(void) | |||
462 | pcntxt_mask, xstate_size); | 462 | pcntxt_mask, xstate_size); |
463 | } | 463 | } |
464 | 464 | ||
465 | /* | ||
466 | * For the very first instance, this calls xstate_enable_boot_cpu(); | ||
467 | * for all subsequent instances, this calls xstate_enable(). | ||
468 | * | ||
469 | * This is somewhat obfuscated due to the lack of powerful enough | ||
470 | * overrides for the section checks. | ||
471 | */ | ||
465 | void __cpuinit xsave_init(void) | 472 | void __cpuinit xsave_init(void) |
466 | { | 473 | { |
474 | static __refdata void (*next_func)(void) = xstate_enable_boot_cpu; | ||
475 | void (*this_func)(void); | ||
476 | |||
467 | if (!cpu_has_xsave) | 477 | if (!cpu_has_xsave) |
468 | return; | 478 | return; |
469 | 479 | ||
470 | /* | 480 | this_func = next_func; |
471 | * Boot processor to setup the FP and extended state context info. | 481 | next_func = xstate_enable; |
472 | */ | 482 | this_func(); |
473 | if (!smp_processor_id()) | ||
474 | xstate_enable_boot_cpu(); | ||
475 | else | ||
476 | xstate_enable(pcntxt_mask); | ||
477 | } | 483 | } |