Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5162538imm; Tue, 19 Jun 2018 06:10:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJPPid/z1oBnmdKb48bCLbb28qZ3ciwxkGnmWhTjlgcHPtM2g+jDX2p9BChYSETY3V6/+zO X-Received: by 2002:a63:730d:: with SMTP id o13-v6mr14786936pgc.1.1529413804197; Tue, 19 Jun 2018 06:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529413804; cv=none; d=google.com; s=arc-20160816; b=L86DDo+4n6HmrWzNyvaDcXoonbgRtNhu+jeyczntH4SHn+fpOkI35Rrki2Vkb3fR2C qlUl+BwAUmbn36XiVxiymAtw4oP5EgTbnODNjVesRLM11H11BXPQFz8sHiYMD7hmgAnL srV1X2qakMpM2edE7BXBTEA2XQIKPoikk7tX5NW4L6BENVSlio5cZ9PM8++geKEK+L/R xutZ5TiLLyTMcIcEmUBjXkYOfLS2F6EnBFUKokXRcB4Rux3i7aM0uRcrs+WO0LrqhARm pRWURMdy3K/lScIOyeB8pBVpDdjOIW8T6i+3tgc57ujgo+jOFiCj9kbPcRk6gnmDGxJL QpKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=MCtSxVxkt36EZl0JKfy5udNkJ4D9kguVbO5djKWXhYw=; b=yFMIkJi77f5+xjRhk1lXHd0u3QeyyBwUveIwbUSdApAo/0i8YDjeDufioGFQ11CXdL cMWS9Nwlbt0h9Cr3Mk4xaaFoh/MIjAFqVnFGFafocKIVOElsFy0iP3dszD7vPsVQ9K4T sleaDuNX6DfalOK5qcemqYdf0lCe6u2hqK8GLl7cLvFehqyAqbuKrJ9YfyHej/Lo6JWC l95yJEfFVSfKV9rLqPCV5rvwDoFJ+37dIjqhr1EOdAW8LwS8kwat3zAgKtZZdSqdYj+J QWzP1Ej/jDLylShDKkYy0lk4DvntiEdSCISbFtQ0sUxDWV5zsD443LV18E8UNl3ywbbK Ty9w== 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 d8-v6si13930219pgq.162.2018.06.19.06.09.44; Tue, 19 Jun 2018 06:10:04 -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 S966373AbeFSNJB (ORCPT + 99 others); Tue, 19 Jun 2018 09:09:01 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:57085 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965720AbeFSNJA (ORCPT ); Tue, 19 Jun 2018 09:09:00 -0400 Received: from hsi-kbw-5-158-153-55.hsi19.kabel-badenwuerttemberg.de ([5.158.153.55] helo=nanos.guests.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fVGNO-0005TJ-A4; Tue, 19 Jun 2018 15:08:50 +0200 Date: Tue, 19 Jun 2018 15:08:44 +0200 (CEST) From: Thomas Gleixner To: David Laight cc: 'Andy Lutomirski' , Dave Hansen , "Jason A. Donenfeld" , Rik van Riel , LKML , X86 ML Subject: RE: Lazy FPU restoration / moving kernel_fpu_end() to context switch In-Reply-To: <8fcc0d8f5d8f48ca92e034d0c1a3c157@AcuMS.aculab.com> Message-ID: References: <6eecf873-9d87-5345-70ba-5c064a31714b@linux.intel.com> <8fcc0d8f5d8f48ca92e034d0c1a3c157@AcuMS.aculab.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Jun 2018, David Laight wrote: > From: Andy Lutomirski > > Sent: 15 June 2018 19:54 > > On Fri, Jun 15, 2018 at 11:50 AM Dave Hansen > > wrote: > > > > > > On 06/15/2018 11:31 AM, Andy Lutomirski wrote: > > > > for (thing) { > > > > kernel_fpu_begin(); > > > > encrypt(thing); > > > > kernel_fpu_end(); > > > > } > > > > > > Don't forget that the processor has optimizations for this, too. The > > > "modified optimization" will notice that between: > > > > > > kernel_fpu_end(); -> XRSTOR > > > and > > > kernel_fpu_start(); -> XSAVE(S|OPT) > > > > > > the processor has not modified the states. It'll skip doing any writes > > > of the state. Doing what Andy is describing is still way better than > > > letting the processor do it, but you should just know up front that this > > > may not be as much of a win as you would expect. > > > > Even with the modified optimization, kernel_fpu_end() still needs to > > reload the state that was trashed by the kernel FPU use. If the > > kernel is using something like AVX512 state, then kernel_fpu_end() > > will transfer an enormous amount of data no matter how clever the CPU > > is. And I think I once measured XSAVEOPT taking a hundred cycles or > > so even when RFBM==0, so it's not exactly super fast. > > If the kernel was entered by a system call do you need to save the AVX512 > state at all? > IIRC the registers are all defined as 'called saved' so there is no expectation > that they will be saved across the syscall wrapper function call. > All you need to do is ensure that 'kernel' values aren't passed back to userspace. > There is a single instruction to zero all the AVX512 registers. Then we need different treatment for exception entries and consecutive preemption. Lots of corner cases to cover ... Thanks, tglx