From: Sebastian Andrzej Siewior Subject: Re: [RFC PATCH 10/10] x86/fpu: defer FPU state load until return to userspace Date: Wed, 19 Sep 2018 19:05:16 +0200 Message-ID: <20180919170515.ptqmmpsxrdjsi64j@linutronix.de> References: <20180912133353.20595-1-bigeasy@linutronix.de> <20180912133353.20595-11-bigeasy@linutronix.de> <650FC457-7E4C-473A-9E5F-EAFC74F6444B@amacapital.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel To: Andy Lutomirski Return-path: Content-Disposition: inline In-Reply-To: <650FC457-7E4C-473A-9E5F-EAFC74F6444B@amacapital.net> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 2018-09-12 08:47:19 [-0700], Andy Lutomirski wrote: > > --- a/arch/x86/kernel/fpu/core.c > > +++ b/arch/x86/kernel/fpu/core.c > > @@ -101,14 +101,14 @@ void __kernel_fpu_begin(void) > > > > kernel_fpu_disable(); > > > > - if (fpu->initialized) { > > + __cpu_invalidate_fpregs_state(); > > + > > + if (!test_and_set_thread_flag(TIF_LOAD_FPU)) { > > Since the already-TIF_LOAD_FPU path is supposed to be fast here, use test_thread_flag() instead. test_and_set operations do unconditional RMW operations and are always full barriers, so they’re slow. okay. > Also, on top of this patch, there should be lots of cleanups available. In particular, all the fpu state accessors could probably be reworked to take TIF_LOAD_FPU into account, which would simplify the callers and maybe even the mess of variables tracking whether the state is in regs. Do you refer to the fpu.initilized check or something else? Sebastian