Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1122272imm; Fri, 15 Jun 2018 11:34:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkuFV0eRqQ7AhZSeAhQYmxlNV5mjwdZtg1HnDzLv0Z6F5H3a1Gv7zQcUJQ5C2IsrvPQrGT X-Received: by 2002:a63:5f0c:: with SMTP id t12-v6mr2538345pgb.95.1529087644553; Fri, 15 Jun 2018 11:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529087644; cv=none; d=google.com; s=arc-20160816; b=NlWCko0BucVX85Jm+eLpfDrXbvNh3RGNToSOMsKQwYyyYkos2bs1FgXe7FcGVpuhy9 cArVONYjdq0n7L13Lroueikz5qF45kGFtIqSi/Bsu9bVzwtzHn7I5wwCGvZZUbozXzwH JOeerY0X4aTM5OWTVOieBR3rWmuinmi6IOpjKWy65tc2azNRPwbPAVq4eODzM6TyTd3l 1Dod87bjHCEEE5sgTF76nMSkQwGr+Icz7OcuteI/eOFwt9lstq3UMQOgUuebVpQjEQrf O8eDReN0tvvAO2RiWtnyji7U4ak4vNGUpbSuaQEVKoByvqpN0qy0uy/amhxCUYcu4C+4 dS5g== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=/8NAJmNYARFyNWzHn+uIP1sczZ2b6YDscWv813K097U=; b=lO7iBf/nQbBbZJrPxkb2PF7Bi/huan4MYCQiLar5emN8gul+NstUTtkZx7JWPVHTVX MJPvOuH6k91MW5awIzvoYixWO4rPpBirsBo9H9RXZaXmwFNelFpoWWhLH/CH/qVux15m GlFgUTtgiYknG47+xlyEZUmi/9T+Bh7hmGzs/dNtnQFruUxzcpBrbjyMOAjY5raP/27q jy5EFEGr7OoD4+Cl33Pnbs7G3Lt5bLGV9naLBMBzrtcXaR0D8W3N0ZJBwxl4BDMg70z6 9CKEP8FRNZwVTnJDGD3amT5WToQCptJ+zDYuq3Uwk8JGuD8m0G9BXoXab+JO/UqJa5AN jCMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fO9TZTBN; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si8531774ple.308.2018.06.15.11.33.50; Fri, 15 Jun 2018 11:34: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fO9TZTBN; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756583AbeFOSdV (ORCPT + 99 others); Fri, 15 Jun 2018 14:33:21 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:50309 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756476AbeFOSdT (ORCPT ); Fri, 15 Jun 2018 14:33:19 -0400 Received: by mail-it0-f68.google.com with SMTP id u4-v6so3994642itg.0 for ; Fri, 15 Jun 2018 11:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/8NAJmNYARFyNWzHn+uIP1sczZ2b6YDscWv813K097U=; b=fO9TZTBN7tYEYp4/OEn8xmbDPgfFgtnu5G2cL+bogZrSvXLhaw/Rqm2pk/xwXORtEY ius43RQRmf62BbZUlLv70226wJFjhwj1F+K7qB99BwKZ1xJ45upB1bgQxbKKUbF71E6t xjmu9OXM7GUegUaIIl0Enyym2MaPZWbQHirhzn6sPS+fryQFcrMU6+8I/BUEMy0LGaBu cLPbHC06jE79xWqL1ctl7RPHtspSTDfV3+91ESyHYfPf1Xwqm7++cQSeW520j/07k1po jPwzYjp0WBJK3lfh5J8hQcuIuEk5PQg+/V6+ae0skl5sfzt7Qyenlgq66k1Z75F0kJbF /NHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/8NAJmNYARFyNWzHn+uIP1sczZ2b6YDscWv813K097U=; b=AzbLZXSI3ok0mCywtwJuoKkbIcP5JDcXoCC7Fcqul7gPIlcfa+GgbDFHjasMyrTN9L 6EEa0mxdWPdZDp/aAMmNQVpqXhZHMS1P7FiJ5l8lYUvxh0LPJRqIba46HSK4VYuhAwWN GqiRNw7sA1Cjfc/BlmyGzCNocgvxWg5jWYbyPMsB9XjoNRO2deGIgsCuqpi/YvytdJgn IfXgZsDtFtEabivNNcs9vybw+ix008JRK3d/oda1z8tXOTGRjGuYomYQ7QTd749UVxwq skKsQLr0WIWmONZJ9SQigd5ZzMxRR/7fj15VDPEzu9d6e/P/ppOqwecvvyn3YW0EZCyk oPmw== X-Gm-Message-State: APt69E2YMnAxIWjstTmne9aMPuW3YwN/W4zKQvp5FfLavyeiLm9yrh0X pwTDd1IJGbgj9oLRrLSoyz8qrcp7JftTTh7WWQ== X-Received: by 2002:a24:eb0e:: with SMTP id h14-v6mr2401507itj.69.1529087599004; Fri, 15 Jun 2018 11:33:19 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:b155:0:0:0:0:0 with HTTP; Fri, 15 Jun 2018 11:33:18 -0700 (PDT) In-Reply-To: References: From: Brian Gerst Date: Fri, 15 Jun 2018 14:33:18 -0400 Message-ID: Subject: Re: Lazy FPU restoration / moving kernel_fpu_end() to context switch To: Thomas Gleixner Cc: "Jason A. Donenfeld" , LKML , X86 ML , Andy Lutomirski , Peter Zijlstra 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 12:25 PM, 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. One optimization that can be done is to delay restoring the user FPU state until we exit to userspace. That way the FPU is saved and restored only once no matter how many times kernel_fpu_begin()/kernel_fpu_end() are called. -- Brian Gerst