Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1182253imm; Fri, 15 Jun 2018 12:35:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ5TPqfgnMFfEo7I+CcUkcCgMF3m2skCfuJ3WVwHSHGCheqa4ws+7c+zyfgaEmLCtsM4Yot X-Received: by 2002:a65:4784:: with SMTP id e4-v6mr2760911pgs.58.1529091325955; Fri, 15 Jun 2018 12:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529091325; cv=none; d=google.com; s=arc-20160816; b=Tt9bsLjLuEzZxVvI12SudMM11nvrnHBzrcVhZ0R8QilYs6yoM1VZFa2AqX1lcKG9D2 HNVd4umduJ+HQFoRSn0neEM9DujPKHZqPpcEuhDSA3n0zFgPGfK/uSVZzaUeRMhW5WuT oOtxmuGB3OxCOMtemHWfblheW0ua7s3OD25JF96mcGS3OjKalwCctPNsXwun+FsWL2if Egebtvtv6/WHEpP/Mhd88JG0yNS/6ztdi+oRHXQwOo18UBQdx7nkMSxayIah2hNMpMai hwEsi+FqTxxxIQWTBdKnbdInqPmng+ToVvzbgR9pY7aN7R3TL/mIw6ml/u6jjMYW7pJj LEwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=5lafXdAvp4KqA5Y2JT8DicmPWcDyn2SJek/oM2IJJ6Q=; b=tuZVaizcp/YjJs58MrlU8AmEBZ6F9emB55v2Tv28Em29OvK0a0mOxWIIb3ZMmCQBTx s1B+ZX9Dt9RWAbdrB6NG67h9yBUaOdbsO2dkN21ghvgJeucA7ApkPFY757x0QKZnmOoX Cw0BMmy9RBOCczjC2dfqTri2m8OxxkbdrkSO+J3OYJ2xPzg20N7dJEn9vwJ0BfMKaMxK P1zHQxKFPiweXKw+kZv78BsVdXPG7YvEiFAbXZhVxl9vtl05PF99+nIflny1u6kf4xo3 LVkALq2hHAssecpDPEMcfyD7Y9cp3WqUAyH7B4XV0tyXmvSN9rKpSurXlzwJiG017HpG JxyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="ZyMU/Yh9"; 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 y83-v6si8487149pfb.284.2018.06.15.12.35.10; Fri, 15 Jun 2018 12:35:25 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b="ZyMU/Yh9"; 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 S966101AbeFOTeq (ORCPT + 99 others); Fri, 15 Jun 2018 15:34:46 -0400 Received: from merlin.infradead.org ([205.233.59.134]:60514 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965768AbeFOTep (ORCPT ); Fri, 15 Jun 2018 15:34:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5lafXdAvp4KqA5Y2JT8DicmPWcDyn2SJek/oM2IJJ6Q=; b=ZyMU/Yh9cBzRcCa530k0zRG8F q/qBj51k4VoMkXDc3jbpptnWaureiqFHk3993gzB8s5yn7dQy4fLQZyXqBWyku9Bfb59X0s6XnBpK iZ5C1Gns6JzgK1BgOTddHiRpIxFuxspm64RTOe2gLrWQxuTahHnYhMTa2s4lgVbTb8vHJR4k84XHo RO41r8dMhut/9I9EoykdjPVUoajMQudpyv+Xl/9UHQ6WohW8i+Pd5/2DzV3gwekdDIwdu/vQ1fLrq /aY/UftLqSJODzkaWtZ5ERGEj44UPDB40Dn5dJs2BnrACrEjq5euVcJbFxbc6+xwGP6PlvCzRkUwU t9XOI3gJA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTuUb-0007Lp-89; Fri, 15 Jun 2018 19:34:41 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7BFE92029FA0B; Fri, 15 Jun 2018 21:34:38 +0200 (CEST) Date: Fri, 15 Jun 2018 21:34:38 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: "Jason A. Donenfeld" , LKML , X86 ML , Andy Lutomirski Subject: Re: Lazy FPU restoration / moving kernel_fpu_end() to context switch Message-ID: <20180615193438.GE2458@hirez.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) 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 06:25:39PM +0200, Thomas Gleixner wrote: > On Fri, 15 Jun 2018, Jason A. Donenfeld wrote: > > In a loop this looks like: > > > > for (thing) { > > kernel_fpu_begin(); > > encrypt(thing); > > kernel_fpu_end(); > > } > > > > This is obviously very bad, because begin() and end() are slow, so > > WireGuard does the obvious: > > > > kernel_fpu_begin(); > > for (thing) > > encrypt(thing); > > kernel_fpu_end(); > > > > This is fine and well, and the crypto API I'm working on will enable > > It might be fine crypto performance wise, but it's a total nightmare > latency wise because kernel_fpu_begin() disables preemption. We've seen > latencies in the larger millisecond range due to processing large data sets > with kernel FPU. > > If you want to go there then we really need a better approach which allows > kernel FPU usage in preemptible context and in case of preemption a way to > stash the preempted FPU context and restore it when the task gets scheduled > in again. Just using the existing FPU stuff and moving the loops inside the > begin/end section and keeping preemption disabled for arbitrary time spans > is not going to fly. Didn't we recently do a bunch of crypto patches to help with this? I think they had the pattern: kernel_fpu_begin(); for (units-of-work) { do_unit_of_work(); if (need_resched()) { kernel_fpu_end(); cond_resched(); kernel_fpu_begin(); } } kernel_fpu_end(); I'd have to go dig out the actual series, but I think they had a bunch of helpers to deal with that.