Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1257805imm; Fri, 15 Jun 2018 13:57:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLhi4ww56qOB6uA8u/SB/jAN6v1R+KeHDcoRS6d5huWPvm0zoIfH0WXpCLvPsqHtL/TnY4A X-Received: by 2002:a17:902:a416:: with SMTP id p22-v6mr3797809plq.228.1529096271935; Fri, 15 Jun 2018 13:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529096271; cv=none; d=google.com; s=arc-20160816; b=LlQSBoUp9Uxm3+W3G2ests2CL+Rjipfvs6Eb7aYVIIRB0CtRvNjeiOAqxtmZvV8ynx mJH5eOpCitmoClCifb/SafRTK1gq5DVauflqoj7exy9trtNG3AAIGBdim5ztVi+wlnAa 8qcIBbK7HJ6QTMSpjdg02opc4b3R8OO5lDxn81DA821VPJoNFTkLtZ2qXOLy7Yn9e8Ek s6qEYcc0cpxNNuIDKQZ5YNJ+Omw3mdiQo6+8gkN9LCMFqwUVNyLWkSbrJi8ZjWwh4563 YqVlLkWF4pJjvZ2tQOjLp5J8cdtYQ0jTvRjqy7okQvEVTWpRM03+bZbX/9fF6WH2SuTx uMwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to:date :cc:to:from:subject:message-id:arc-authentication-results; bh=L92hkDAuUl3z/UuAHPvOj43lhg1Sl93aS6G64V6Q2KA=; b=JCNPXWOpqjmp9VxI7UWcIX/HVR3Idv+o04XS7oFm+HuiHeULpC1JPkUkLOHWdHtewV LgDaNueDuxColSOe6sHbVwpW5s1a6spXmZICr4wwzEsRQ7LmsRVOqGjKAo/RztGI3kL5 A/60w4oJYd9RgBfNuqltUOg6XL/OzSOL/WgMweZqAFuLBkk4wMruzZ2R7foewL16ePoI AkprC4BX6Yga8QWNGGCRZh4uH0EWTufl3feyOvHkCYzO+XzuDQ2+VFnWkZsRDI5QnwO6 J59hkOCBzODp6HRGNMPw2vrdrKv//+6ZXMGbdhLiOBC5viMAEpChHSmIoYten59KPZmT SE2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9-v6si7380570pgf.60.2018.06.15.13.57.37; Fri, 15 Jun 2018 13:57:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756465AbeFOU5B (ORCPT + 99 others); Fri, 15 Jun 2018 16:57:01 -0400 Received: from shelob.surriel.com ([96.67.55.147]:34402 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753541AbeFOU5A (ORCPT ); Fri, 15 Jun 2018 16:57:00 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fTvmF-0005gk-1i; Fri, 15 Jun 2018 16:56:59 -0400 Message-ID: <1529096218.7898.158.camel@surriel.com> Subject: Re: Lazy FPU restoration / moving kernel_fpu_end() to context switch From: Rik van Riel To: Dave Hansen , "Jason A. Donenfeld" , Andrew Lutomirski Cc: LKML , X86 ML Date: Fri, 15 Jun 2018 16:56:58 -0400 In-Reply-To: <7e415c4d-415b-0ff6-5488-1681e522d2dc@linux.intel.com> References: <7e415c4d-415b-0ff6-5488-1681e522d2dc@linux.intel.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-YBC3ZSL+colrEHF43o3A" X-Mailer: Evolution 3.26.6 (3.26.6-1.fc27) Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-YBC3ZSL+colrEHF43o3A Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2018-06-15 at 13:42 -0700, Dave Hansen wrote: > On 06/15/2018 01:33 PM, Jason A. Donenfeld wrote: > > On Fri, Jun 15, 2018 at 8:32 PM Andy Lutomirski > > wrote: > > > quite in the form you imagined. The idea that we've tossed > > > around is > > > to restore FPU state on return to user mode. Roughly, we'd > > > introduce > > > a new thread flag TIF_FPU_UNLOADED (name TBD). > > > prepare_exit_to_usermode() would notice this flag, copy the > > > fpstate to > > > fpregs, and clear the flag. (Or maybe exit_to_usermode_loop() -- > > > No > > > one has quite thought it through, but I think it should be > > > outside the > > > loop.) We'd update all the FPU accessors to understand the flag. > >=20 > > Yes! This is exactly what I was thinking. Then those calls to > > begin() > > and end() could be placed as close to the actual FPU usage as > > possible. >=20 > Andy, what was the specific concern about PKRU? That we might do: >=20 > kernel_fpu_begin(); <- Saves the first time > something() > kernel_fpu_end(); <- Does not XRSTOR >=20 > copy_from_user(); <- Sees old PKRU, does the wrong thing >=20 > prepare_exit_to_usermode(); <- Does the XRSTOR > // only now does PKRU have the right value > SYSRET/IRET >=20 > ? >=20 > Does that *matter* unless something() modified PKRU? We could just > make > the rule that nobody is supposed to mess with it and that it's not > covered by kernel_fpu_begin/end() semantics. We could even > theoretically enforce that in a debug environment if we watch its > value. KVM needs to change out guest and host PKRU values when switching between guest and host mode, but since f775b13eedee ("x86,kvm: move qemu/guest FPU=20 switching out to vcpu_run") that no longer happens under kernel_fpu_begin/end so we don't need to care about that :) --=20 All Rights Reversed. --=-YBC3ZSL+colrEHF43o3A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEKR73pCCtJ5Xj3yADznnekoTE3oMFAlskKBoACgkQznnekoTE 3oOx9QgAka+/LeW7LyIzrZh6JE+0ctj35QONbWRvOMWdsAge1+J7MM65isl3ihPD 6KHJQ93GxvF3YI/md+PfmOyWv/teVtW0sVq7j8rIczGGMS+G5jdzofR3sN+U+Idy /Aba9lfG0U+kPP+XqS/aOQmCBCCQbwukUUJurED5glfMyxbncEqgG/IjQxCW3MYJ 7ltMzl2gilo6rleJlMgDObj4eMAnNcCjP3WawiABcRpWP3SORCAZsVyQT3D+2i0/ fObkqGvEjRn6eUPt3UinoP7wpiPrOcC8NgipxvgdpwErSzdhrLv0QYkYQVrxpapB du11W8DdxPm92O5DXIepCdM1REs83g== =Ai7+ -----END PGP SIGNATURE----- --=-YBC3ZSL+colrEHF43o3A--