Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1254489imm; Fri, 15 Jun 2018 13:53:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK31GYQe5Z4c6x41v9UtFfnwVVZMPFebueHWkUTr7AXy+eGGEH4PXwgUX8JuR+eiMfQB5QE X-Received: by 2002:a17:902:4203:: with SMTP id g3-v6mr3671612pld.315.1529096022134; Fri, 15 Jun 2018 13:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529096022; cv=none; d=google.com; s=arc-20160816; b=kV6c11W061IXTXBm6T2HWMLTR4bHMD8Xwicl2sr1BodYqWevNye0bjy1+yQEOF01YU 5sb3he5wVM6EHhiypBNB2xbmAIrpFgO7PPEHuwDt+k8bIVyWZhES9gv0nE4Wv/TXr8oy 5eZ1i7erDbXBDwfv49JAfbWZiaRCtIluUAnBvKTJDOexByZqIB3t8sHZFGyOL7aAycJ5 mMLbZ1oncG5yRXdWC0G7cMvtBMGR/iG1YtHP2VT5RxZ+AqU5mq1mRPL4jbl+1N/ue0dB 0YN5n6kOJcQbED4mo2vL0lXtZxb9W5Ej28dxOb+aPVglUFymoaCRHZn1Ooz+LRyvEJ6o 7O/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=GQOfyOBP4BLZRNnR0h2nyzfHrJobDZh+lT/NQfeAsC8=; b=weLe2bTMuah4u2xKuASK5F662qW3Nnjl6B5kcGwHE/lfEObnFWdh9wpTnx2PeIGABB 9YItgOILsCpOIq2tMip77qCcjP+DQ++MGpF89I8KFAs1axbpHMK+Lp+aZmexVGqWp6xu 4LPPFUoooybKtkqQw4KIJqYLYU93zphRjvBoqHHNiS4a3weHztx8ecBBS0aloer7zmha iSF/m04vLUyOAwncYehO5TA9FFQB423Zp7rWxDjL9lZx8gMDgWbC+SlmClt6Mb7/0ObN f6ln5UxI/GMJ37vhhJa+QugtE7rmdGjqytGpyxIfWUeVUVGHzTI0s7La78XK2wa/qagq BAnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=LvgO4zrs; 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 85-v6si8405103pfm.264.2018.06.15.13.53.27; Fri, 15 Jun 2018 13:53:42 -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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=LvgO4zrs; 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 S1756496AbeFOUw3 (ORCPT + 99 others); Fri, 15 Jun 2018 16:52:29 -0400 Received: from mail-pl0-f45.google.com ([209.85.160.45]:40044 "EHLO mail-pl0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756337AbeFOUw2 (ORCPT ); Fri, 15 Jun 2018 16:52:28 -0400 Received: by mail-pl0-f45.google.com with SMTP id t12-v6so5920110plo.7 for ; Fri, 15 Jun 2018 13:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=GQOfyOBP4BLZRNnR0h2nyzfHrJobDZh+lT/NQfeAsC8=; b=LvgO4zrsap6mwLW1o4uQiVKcTaUuWbVlq1YQQ8zNRfT9j00ulG9ofzXPcLNE+G6ZCH hPFbgQZcYNhXqtywqBRZbyEtzEF8u+SRPzC8R9++lr41iG58euPfvx8QyfVpSQL3CEiG wX9LYXNWNrLbruEDulhTK0msyssy1Kyl1FdDwq4gZdUNZhAdkkjC3J8TD+FhJShKipVV NkuVYWoVl7norFewpzPDep6WhqFD907K6u9kihaYovjO11dHZ4JWhHARPqMcrM6WigmN bPdUg9pB/UP8o+vLzcjFTFNETPjtDqw4jIlmJGzg9TP0TQvnob8L8WUUmqbM/7NJg5VO zJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=GQOfyOBP4BLZRNnR0h2nyzfHrJobDZh+lT/NQfeAsC8=; b=ZG6Of7+WG18HvxK+kLbVikdQhuWdBGO5Oow/vtvZb7V+eIbj/TbSkux4I5BOk238zf n7cZJ+1UQcIM2em5h0++hiyJtXaipeInpFS5a0lrBfs8rHEb/RBqhVd0EuhcUPwW7Djr oZgJLrduUFo7B40pVLrADgE3pTzPF29SO2Fc3H+ab7n6uKKBnLFFgtJgBuy4nhQO2VRR IdGlZcvH9PBcEkJiBY5dPpQS3gpW5k3/W/ue1v5oUZ2ysEOxIUVWcjdKbbe+m1r8Svgm Joy31ParbWqJD0evx9Jaugj3lTheK91kTiqu7QEAMJiW1/JbKt5gDbciFn+2zA1AIi9n X36w== X-Gm-Message-State: APt69E1i5i64FbkjlpwkaVCBf2I7E0t+O4nI9Vn89c0DTi0bDDbplMKL 0McOJdxVVNBilR277wJ6M25K/w== X-Received: by 2002:a17:902:8d86:: with SMTP id v6-v6mr324500plo.325.1529095948161; Fri, 15 Jun 2018 13:52:28 -0700 (PDT) Received: from ?IPv6:2600:1010:b063:8990:3528:189a:5bff:5f2f? ([2600:1010:b063:8990:3528:189a:5bff:5f2f]) by smtp.gmail.com with ESMTPSA id y81-v6sm14014028pfd.178.2018.06.15.13.52.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jun 2018 13:52:27 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: Lazy FPU restoration / moving kernel_fpu_end() to context switch From: Andy Lutomirski X-Mailer: iPhone Mail (15F79) In-Reply-To: <7e415c4d-415b-0ff6-5488-1681e522d2dc@linux.intel.com> Date: Fri, 15 Jun 2018 13:52:25 -0700 Cc: "Jason A. Donenfeld" , Andrew Lutomirski , riel@surriel.com, LKML , X86 ML Content-Transfer-Encoding: quoted-printable Message-Id: <63A4C722-A37E-49A8-96AC-57BFD0B2DAAB@amacapital.net> References: <7e415c4d-415b-0ff6-5488-1681e522d2dc@linux.intel.com> To: Dave Hansen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jun 15, 2018, at 1:42 PM, Dave Hansen wro= te: >=20 >> 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. >> 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. Indeed, this case seems highly unlikely. I was imagining we have two tasks. T= ask A enters the kernel and sleeps. Task B runs and gets its PKRU loaded. Th= en it enters the kernel and we switch back to A. Now we have A=E2=80=99s FPU= state in memory and B=E2=80=99s PKRU in the register. If A does copy_to_use= r, we lose.=