Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1137092imm; Fri, 15 Jun 2018 11:50:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI2yt6KrAssv8YplO7IgdhPQiG6qeQjmbffPDYXjxiVKLR4Go5oBweO9aMdovJSzCMvNcwL X-Received: by 2002:a62:c00e:: with SMTP id x14-v6mr3203308pff.67.1529088643207; Fri, 15 Jun 2018 11:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529088643; cv=none; d=google.com; s=arc-20160816; b=dO/bhO+AnvRrun5LiEGZR1SwZBwFBslC4ww4kKVdXuVKedmQBsQr0wu1ltIcCaz/fg gtmn/9FhE5QhfrUvALhz6+gyJQEqtuJvGlk8EDDYBpIyL+kP0oF3dOTkNc4OtLKJs8Wg OiFW77tmR7W849B0WOqcIU/IWUivFVdKBAAH+RUUkCfrZzuZVO6wbxID5D4iAXWQyPcs ycmVkEEPl3Mrs3Yy91g45A1xjVMnibAN+E1Iwp5Xsh78rUPdx7hjZfAzmPWLSq30WUXQ a4rt8qGcW/+wUXNkmhEHfNPWxAHUl/BA5w5lmENnej78QuYEM+FWtUykzriCaIweb1up /NEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=IThtW6U9BEGOV1qS542FKsVjKB8NC8GMwwTbxFvCvvc=; b=cg8EQRWnFdqjSXoya9vvxyzUNvjD7EhypWVcjiNagZieLGu092Jn+oWJgdgLveq9Vg 6/UfWXVar9PD8ABXF+IPxWeG+prQj6Wmu56Qqhn2Uba8JjRZ/zzNr5OBJd6QHjHfWxtn WGL2b7WNoF6d48IgLq0Apa/KFePj0Xgqtbpq4aP3xjS4s0PCyuwHgacXFTMZ7ChaKUqW sfksEcFeRsnSBy+S7d4Bff5IWVG2uxrHLrzSM4yPRcntyNFJSBUE5lAjnxCQQ1ZQNkPy Ye/QNH8QCk0fTS/ioZROby7GgwJaFUMQYk/EQENOKhi12giWoriL5daxVcCF6ixl4K9W H3mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mJ+mp2lO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11-v6si8558455plq.33.2018.06.15.11.50.28; Fri, 15 Jun 2018 11:50:43 -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=@kernel.org header.s=default header.b=mJ+mp2lO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756364AbeFOSuF (ORCPT + 99 others); Fri, 15 Jun 2018 14:50:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:35096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756299AbeFOSuE (ORCPT ); Fri, 15 Jun 2018 14:50:04 -0400 Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E520A208E1 for ; Fri, 15 Jun 2018 18:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529088604; bh=aKafc1FFuiPvRXbw4WkNPXm736JSnKh+WTqcmV8T2kg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mJ+mp2lOPlXC//kiGd94Jdt5H7kbIaM42L9yX0zkxVQetfOu4nYkORtf2yYZ+ANLT L1u25atGkFu8qbvHzX2ZuPdpwpv4OOaYBelV5JSnjdgN42uholfekvXdB7kNlTGtf6 WTfbO+9VIbEhttu0k0+rBr6F/w1mckSybxcZso5c= Received: by mail-wm0-f49.google.com with SMTP id v16-v6so4973580wmh.5 for ; Fri, 15 Jun 2018 11:50:03 -0700 (PDT) X-Gm-Message-State: APt69E3wMtmDFmJd+wAWgW9BJI22msD4cynRqQN8t/we2nhB6hxSkcmE DZB6OXnDwFmijltZdvPMG36PpUUoRFTdX664mOfTHQ== X-Received: by 2002:a1c:34c9:: with SMTP id b192-v6mr2190945wma.21.1529088602388; Fri, 15 Jun 2018 11:50:02 -0700 (PDT) MIME-Version: 1.0 References: <368b8069-0463-6161-d603-10769fd2ec57@linux.intel.com> In-Reply-To: <368b8069-0463-6161-d603-10769fd2ec57@linux.intel.com> From: Andy Lutomirski Date: Fri, 15 Jun 2018 11:49:50 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Lazy FPU restoration / moving kernel_fpu_end() to context switch To: Dave Hansen Cc: Andrew Lutomirski , "Jason A. Donenfeld" , Rik van Riel , LKML , X86 ML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 15, 2018 at 11:43 AM Dave Hansen wrote: > > On 06/15/2018 11:31 AM, Andy Lutomirski wrote: > > Using WRPKRU is easy, but, > > unless we do something very clever, actually finding PKRU in the > > in-memory fpstate image may be slightly nontrivial. > > Why? > > It's at a constant offset during any one boot, for sure. XSAVEC/XSAVES > can move it around, but only if you change the Requested Feature BitMap > (RFBM) that we pass to XSAVES or change the control register that > enables XSAVE states (XCR0). > > We don't change XCR0 after boot, and RFBM is hard-coded to -1 as far as > I remember. I thought that XSAVES didn't allocate space for parts of the state that are in the init state. I guess I was wrong :) So never mind, context switch should just need to WRPKRU the field at the predetermined offset in fpstate for the new task. And, if some appropriate debug option is set, it should warn if TIF_FPU_UNLOADED is clear for the new task. I suspect that the whole patch should only be a couple hundred lines of code. And I think there are VM workloads where it would be a *huge* win. --Andy