From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757464AbcAYPks (ORCPT ); Mon, 25 Jan 2016 10:40:48 -0500 Received: from mga01.intel.com ([192.55.52.88]:63283 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752388AbcAYPkp (ORCPT ); Mon, 25 Jan 2016 10:40:45 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,345,1449561600"; d="scan'208";a="641129554" Subject: Re: [PATCH v2 2/5] x86/fpu: Fix FNSAVE usage in eagerfpu mode To: Andy Lutomirski , x86@kernel.org, linux-kernel@vger.kernel.org References: <60662444e13c76f06e23c15c5dcdba31b4ac3d67.1453675014.git.luto@kernel.org> Cc: Borislav Petkov , Fenghua Yu , Oleg Nesterov , Peter Zijlstra , Sai Praneeth Prakhya , yu-cheng yu , Rik van Riel , Linus Torvalds From: Dave Hansen Message-ID: <56A641FC.1030302@linux.intel.com> Date: Mon, 25 Jan 2016 07:40:44 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <60662444e13c76f06e23c15c5dcdba31b4ac3d67.1453675014.git.luto@kernel.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/24/2016 02:38 PM, Andy Lutomirski wrote: > if (fpu->fpregs_active) { > + /* > + * Ignore return value -- we don't care if reg state > + * is clobbered. > + */ > copy_fpregs_to_fpstate(fpu); > } else { > this_cpu_write(fpu_fpregs_owner_ctx, NULL); > @@ -189,8 +193,12 @@ void fpu__save(struct fpu *fpu) > > preempt_disable(); > if (fpu->fpregs_active) { > - if (!copy_fpregs_to_fpstate(fpu)) > - fpregs_deactivate(fpu); > + if (!copy_fpregs_to_fpstate(fpu)) { > + if (use_eager_fpu()) > + copy_kernel_to_fpregs(&fpu->state); > + else > + fpregs_deactivate(fpu); > + } > } > preempt_enable(); I wonder if we should just make the > + if (use_eager_fpu()) > + copy_kernel_to_fpregs(&fpu->state); > + else > + fpregs_deactivate(fpu); behavior the default _inside_ copy_fpregs_to_fpstate(fpu). We evidently got it wrong in 2/3 of the call sites that needed it. It ends up being an optimization for FNSAVE (because it allows us to avoid an FRSTOR), but we only take advantage of that in cases of kernel_fpu_begin/end(). FXSAVE has been around since at _least_ 1999, and I'd expect it to get used in place of FNSAVE everywhere that it is available. If we don't want to do that, maybe we should add a "clobber" argument to copy_fpregs_to_fpstate() for when it's allowed to clobber the register state. I just hate putting this logic at all the call sites.