From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <1431700304.6315.117.camel@decadent.org.uk> Subject: Re: [ 05/48] x86_64, switch_to(): Load TLS descriptors before switching DS and ES From: Ben Hutchings To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Andy Lutomirski , Andi Kleen , Linus Torvalds , Ingo Molnar Date: Fri, 15 May 2015 15:31:44 +0100 In-Reply-To: <1431699933.6315.115.camel@decadent.org.uk> References: <20150515080530.510828652@1wt.eu> <1431693140.6315.109.camel@decadent.org.uk> <20150515133820.GA30744@1wt.eu> <1431699933.6315.115.camel@decadent.org.uk> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-6s8coYNorJKVvQhIwajL" Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: --=-6s8coYNorJKVvQhIwajL Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2015-05-15 at 15:25 +0100, Ben Hutchings wrote: > On Fri, 2015-05-15 at 15:38 +0200, Willy Tarreau wrote: > > Hi Ben, > >=20 > > On Fri, May 15, 2015 at 01:32:20PM +0100, Ben Hutchings wrote: > > > On Fri, 2015-05-15 at 10:05 +0200, Willy Tarreau wrote: > > > > 2.6.32-longterm review patch. If anyone has any objections, please= let me know. > > > >=20 > > > > ------------------ > > > >=20 > > > > From: Andy Lutomirski > > > >=20 > > > > commit f647d7c155f069c1a068030255c300663516420e upstream. > > > >=20 > > > > Otherwise, if buggy user code points DS or ES into the TLS > > > > array, they would be corrupted after a context switch. > > > >=20 > > > > This also significantly improves the comments and documents some > > > > gotchas in the code. > > > >=20 > > > > Before this patch, the both tests below failed. With this > > > > patch, the es test passes, although the gsbase test still fails. > > > [...] > > >=20 > > > This depends on the changes to FPU/MMX/SSE state management that you > > > didn't apply to 2.6.32. Note this comment: > > >=20 > > > /* Must be after DS reload */ > > > unlazy_fpu(prev_p); > >=20 > > Are you sure you're not confusing with another one ? When running > > estest without this patch, I get "FAIL: ES corrupted 1000/1000 times" > > while I get "OK: ES was preserved" once applied, so it does seem to > > do what it's intended for. > > > > Also I'm not seeing any reference to the comment above in the patch > > nor around it, which leaves me confused :-/ >=20 > v2.6.32.65:arch/x86/kernel/process_64.c:425: /* Must be after DS reloa= d */ >=20 > If this comment is correct then the patch will cause a regression for > FPU state management. The comment was introduced by: >=20 > commit 0a5ace2ab08d45cd78d7ef0067cdcd5c812ac54f > Author: Andi Kleen > Date: Thu Oct 5 18:47:22 2006 +0200 >=20 > [PATCH] x86-64: Fix FPU corruption And that replaced a longer comment that said "the AMD workaround requires it to be after DS reload". The comment above clear_fpu_state() says: /* AMD CPUs don't save/restore FDP/FIP/FOP unless an exception is pending. Clear the x87 state here by setting it to fixed values. The kernel data segment can be sometimes 0 and sometimes new user value. Both should be ok. Use the PDA as safe address because it should be already in L1. */ Hopefully Andi can explain further if needed; I have no idea. Ben. --=20 Ben Hutchings It is impossible to make anything foolproof because fools are so ingenious. --=-6s8coYNorJKVvQhIwajL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIVAwUAVVYDVee/yOyVhhEJAQouyw/9GCPehe9vTDl0FN2bRlesQuejxZVR2anF CKCKi1mE4piqx2JrzAJDkggqjMkaVKE0qiX69ycfTL3AVFVTxjWPlfH8Tt1IXW3p ibB+CvcH7Pg1Mr/2H1KfXq+Vz/br06W6aG3SWc3VkZTgliNeB9YMrwH+cnZrQ07Q i5Xkcolv8PlVCs5hIfcvIKUil3yeDcdHJYUdTbVPstJLJDbSqUviGoK1zfXzVRoJ sZFq8E3iqbd2lfyKeGdaa7x4keIoo/gvPXJ5x9s6W7rngvltOltuvz8PYQ+iP87U VDxrgl8LCGyj9Ngo/mA211se6yodRi45KKiDQNM1EaL6gPBQbayYxxjtlRKIfc7R vmHMTOhfmupubNKLL3YbMJhgqY/SUGE12C6v/ajNjSPvEXo2CFzPUIxoAzJMTvBk UG37Jf8mA7fSyxiOIa9sLXg//WwA9smj+Tv5Z3AwAdDoNka2m6/CicybC5NNn85M 4cvBygoHCDTAwZVCSMRTEA3LyGJK/RLfBTCTuZS2Oy8rpcp6T1V+2kp/g9WF74SZ yGS/AnS9t6AgYHV8zX0Drxz+5diuqAQ2Kt5lSKmGPwk1SjguAEURHDdiPgx9HTNA FhXdc7AXMecrM80Zalo77FbaAjZK5OwM6aOubsB+GJu9zaCaFpEk3l+F7oFa8KQR k26afCswCyY= =TT79 -----END PGP SIGNATURE----- --=-6s8coYNorJKVvQhIwajL--