Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030839AbbEERxz (ORCPT ); Tue, 5 May 2015 13:53:55 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:36755 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762261AbbEERxw (ORCPT ); Tue, 5 May 2015 13:53:52 -0400 From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Thomas Gleixner Subject: [PATCH 142/208] x86/fpu: Factor out FPU hw activation/deactivation Date: Tue, 5 May 2015 19:50:34 +0200 Message-Id: <1430848300-27877-64-git-send-email-mingo@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430848300-27877-1-git-send-email-mingo@kernel.org> References: <1430848300-27877-1-git-send-email-mingo@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3827 Lines: 143 We have repeat patterns of: if (!use_eager_fpu()) clts(); ... to activate FPU registers, and: if (!use_eager_fpu()) stts(); ... to deactivate them. Encapsulate these in: __fpregs_activate_hw(); __fpregs_activate_hw(); and use them accordingly. Doing this synchronizes the idiom with the fpu->fpregs_active software-flag's handling functions, creating clear patterns of: __fpregs_activate_hw(); __fpregs_activate(fpu); etc., which improves readability. Reviewed-by: Borislav Petkov Cc: Andy Lutomirski Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/include/asm/fpu/internal.h | 32 ++++++++++++++++++++++++-------- arch/x86/kernel/fpu/core.c | 7 +++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index de19fc53f54e..28556c6671c3 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 2fb7a77872cd..43689660d71c 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(); -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/