From: Rik van Riel Subject: Re: [RFC PATCH 04/10] x86/fpu: eager switch PKRU state Date: Wed, 12 Sep 2018 11:30:10 -0400 Message-ID: References: <20180912133353.20595-1-bigeasy@linutronix.de> <20180912133353.20595-5-bigeasy@linutronix.de> <181B4EB8-9FEB-415C-8069-192FB8A5B418@amacapital.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-9uLlLkQIutZ/7ofX5Ed9" Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , Radim =?UTF-8?Q?Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" To: Andy Lutomirski , Sebastian Andrzej Siewior Return-path: In-Reply-To: <181B4EB8-9FEB-415C-8069-192FB8A5B418@amacapital.net> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org --=-9uLlLkQIutZ/7ofX5Ed9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 2018-09-12 at 08:20 -0700, Andy Lutomirski wrote: > >=20 > > --- a/arch/x86/mm/pkeys.c > > +++ b/arch/x86/mm/pkeys.c > > @@ -18,6 +18,20 @@ > >=20 > > #include /* boot_cpu_has, > > ... */ > > #include /* > > vma_pkey() */ > > +#include > > + > > +void write_pkru(u32 pkru) > > +{ > > + if (!boot_cpu_has(X86_FEATURE_OSPKE)) > > + return; > > + > > + current->thread.fpu.pkru =3D pkru; > > + >=20 > I thought that the offset of PKRU in the xstate was fixed after boot. You are right, it is. However, that offset would need to be stored somewhere, and the value read every time we wanted to read or store the PKRU value from/to the floating point state. I suspect that would not be any faster than keeping a copy of the PKRU value in a known location. > Anyway, as written, this needs a lockdep assertion that we=E2=80=99re not > preemptible, an explicit preempt_disable(), or a comment explaining > why it=E2=80=99s okay if we get preempted in this function. >=20 > > + __fpregs_changes_begin(); This handles the preemption disabling, see patch 3 of the series. > > + __fpregs_load_activate(¤t->thread.fpu, > > smp_processor_id()); > > + __write_pkru(pkru); > > + __fpregs_changes_end(); > > +} > >=20 > > int __execute_only_pkey(struct mm_struct *mm) > > { > > --=20 > > 2.19.0 > >=20 >=20 >=20 --=20 All Rights Reversed. --=-9uLlLkQIutZ/7ofX5Ed9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEKR73pCCtJ5Xj3yADznnekoTE3oMFAluZMQIACgkQznnekoTE 3oMCngf+MQ5EGK03pITbeTj/SLYeCBLG2MaNDq5exs5NICa6GLbattuWAGfUI7Ez SmUdvWTWGnWCS9OUxm7wo0P1VWOjuaxE21maRQXai9SaMUzAF7iR3QeYCcBJP5L9 6IutHmElE4LPLvY7YT3wvv6Dq8uLEZ/fOns567fQsMGqiA8MISUxsN/mo4tHimsS M/GgjD+g3wX+Rft74lVwRW/0hRTWR97dkrnX1YPz5Oxp2jIha2TcAK0visaSlujy 3WF0EUgDJBpgU6iVraX4mc3xHu0/aCfCJKMtIC4ghj4q6SM+eGMKpX/asGLOleAN K8GdwbUz1LR+ShLMzu0olhqSUB/ciA== =rdjP -----END PGP SIGNATURE----- --=-9uLlLkQIutZ/7ofX5Ed9--