diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index de19fc53f54e342c673149a9ab43f36415d758b9..28556c6671c31c9666c13724253b6b2bbcec62a7 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -324,14 +324,31 @@ static inline int restore_fpu_checking(struct fpu *fpu) return fpu_restore_checking(fpu); } -/* Must be paired with an 'stts' after! */ +/* + * Wrap lazy FPU TS handling in a 'hw fpregs activation/deactivation' + * idiom, which is then paired with the sw-flag (fpregs_active) later on: + */ + +static inline void __fpregs_activate_hw(void) +{ + if (!use_eager_fpu()) + clts(); +} + +static inline void __fpregs_deactivate_hw(void) +{ + if (!use_eager_fpu()) + stts(); +} + +/* Must be paired with an 'stts' (fpregs_deactivate_hw()) after! */ static inline void __fpregs_deactivate(struct fpu *fpu) { fpu->fpregs_active = 0; this_cpu_write(fpu_fpregs_owner_ctx, NULL); } -/* Must be paired with a 'clts' before! */ +/* Must be paired with a 'clts' (fpregs_activate_hw()) before! */ static inline void __fpregs_activate(struct fpu *fpu) { fpu->fpregs_active = 1; @@ -362,16 +379,14 @@ static inline int user_has_fpu(void) */ static inline void fpregs_activate(struct fpu *fpu) { - if (!use_eager_fpu()) - clts(); + __fpregs_activate_hw(); __fpregs_activate(fpu); } static inline void fpregs_deactivate(struct fpu *fpu) { __fpregs_deactivate(fpu); - if (!use_eager_fpu()) - stts(); + __fpregs_deactivate_hw(); } static inline void drop_fpu(struct fpu *fpu) @@ -455,8 +470,9 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu) new_fpu->counter++; __fpregs_activate(new_fpu); prefetch(&new_fpu->state); - } else if (!use_eager_fpu()) - stts(); + } else { + __fpregs_deactivate_hw(); + } } else { old_fpu->counter = 0; old_fpu->last_cpu = -1; diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index a407bf5cb92f9b3a818ad90e6981932b8220faf6..a617aac1cf81508a846dec7b844cb85df189a25a 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -105,8 +105,7 @@ void __kernel_fpu_begin(void) copy_fpregs_to_fpstate(fpu); } else { this_cpu_write(fpu_fpregs_owner_ctx, NULL); - if (!use_eager_fpu()) - clts(); + __fpregs_activate_hw(); } } EXPORT_SYMBOL(__kernel_fpu_begin); @@ -118,8 +117,8 @@ void __kernel_fpu_end(void) if (fpu->fpregs_active) { if (WARN_ON(restore_fpu_checking(fpu))) fpu_reset_state(fpu); - } else if (!use_eager_fpu()) { - stts(); + } else { + __fpregs_deactivate_hw(); } kernel_fpu_enable();