Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935553AbcJRAGQ (ORCPT ); Mon, 17 Oct 2016 20:06:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48148 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753763AbcJRAGK (ORCPT ); Mon, 17 Oct 2016 20:06:10 -0400 Message-ID: <1476749166.23685.8.camel@redhat.com> Subject: Re: [PATCH RFC 3/3] x86/fpu: defer FPU state load until return to userspace From: Rik van Riel To: Andy Lutomirski Cc: "linux-kernel@vger.kernel.org" , Ingo Molnar , Borislav Petkov , Linus Torvalds , Andrew Lutomirski , dave.hansen@intel.linux.com, Thomas Gleixner , "H. Peter Anvin" Date: Mon, 17 Oct 2016 20:06:06 -0400 In-Reply-To: References: <1476734984-13839-1-git-send-email-riel@redhat.com> <1476734984-13839-4-git-send-email-riel@redhat.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-Ia1eUbyb3gbQWPsitHK7" Mime-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Oct 2016 00:06:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2802 Lines: 71 --=-Ia1eUbyb3gbQWPsitHK7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 2016-10-17 at 13:58 -0700, Andy Lutomirski wrote: > On Mon, Oct 17, 2016 at 1:09 PM,=C2=A0=C2=A0 wrote: > >=20 > > From: Rik van Riel > >=20 > > Defer loading of FPU state until return to userspace. This gives > > the kernel the potential to skip loading FPU state for tasks that > > stay in kernel mode, or for tasks that end up with repeated > > invocations of kernel_fpu_begin. > > =C2=A0#define CREATE_TRACE_POINTS > > =C2=A0#include > > @@ -189,6 +190,14 @@ __visible inline void > > prepare_exit_to_usermode(struct pt_regs *regs) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (unlikely(cached_fla= gs & EXIT_TO_USERMODE_LOOP_FLAGS)) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0exit_to_usermode_loop(regs, cached_flags); > >=20 > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* Reload ti->flags; we may = have rescheduled above. */ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0cached_flags =3D READ_ONCE(t= i->flags); >=20 > Stick this bit in the "if" above, please. Will do. > But I still don't see how this can work correctly with PKRU. OK, Andy and I talked on IRC, and we have some ideas on how to fix & improve this series: 1) pin/unpin_fpregs_active to prevent leaking of other =C2=A0 =C2=A0users' fpregs contents to userspace (patch 1) 2) eagerly switch PKRU state (only), at task switch time, =C2=A0 =C2=A0if the incoming task has different protection keys from =C2=A0 =C2=A0the outgoing task (somewhat unlikely), just like the =C2=A0 =C2=A0KVM vcpu entry & exit code is already doing 3) remove stts from the KVM VMX code (Andy may get =C2=A0 =C2=A0to this before me) 4) enhance __kernel_fpu_begin() to take an fpu argument, =C2=A0 =C2=A0and let the caller (really just kvm_load_guest_fpu) =C2=A0 =C2=A0know whether that fpu state is still present in the =C2=A0 =C2=A0registers, allowing it to skip __copy_kernel_to_fpregs --=20 All Rights Reversed. --=-Ia1eUbyb3gbQWPsitHK7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJYBWduAAoJEM553pKExN6DMDAIAIH78fGALXPGIep6m4eY7tyY UyrOMld5Etq8Z9w/wBuniNJ50sStVOB4ZRDHuOWDrepjH0dI+nzlupzNsmvM1LD/ 8XnKEKd2J7ndg96C+Dprxy8uyWxF9is20+joOK0PQoT0QyAQwurafUaTv1sXWw6P b3kCn/CFbQhX2ex/pGav7IPiqOwwiAc5BoUj59M1pHXgbvzZvD0H7Zxni7+wX9js CFmM57HTBlGTjtNUu+8V5nS0K5tsEL0OZ+LuU6fyxHriTEW/hpORlKGAV8vDggHR SjRWvY54NbRgFb6L3q6dhkVPYn628x0sLp+ogIKfNzh01GDowEcV8ZQtqeTedt4= =eLHE -----END PGP SIGNATURE----- --=-Ia1eUbyb3gbQWPsitHK7--