Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp2952773ybn; Thu, 26 Sep 2019 21:37:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSbRuSCX0SpqxnGIk2+qlWUyycG6/4TM+8o0MqfcsdfxOlaWq8N2SCW1ix6RY+ojlJeEUU X-Received: by 2002:a50:b7ed:: with SMTP id i42mr2398344ede.52.1569559043859; Thu, 26 Sep 2019 21:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569559043; cv=none; d=google.com; s=arc-20160816; b=0JhhjISv+oVJk3V+a1NZU8ONKBJPobTXhncpOe00gkCRJSKUHpT+47b+4wbgfI//IU dQIO2y4R77ZjCTacU3Zk3dakJN71rX27uxDqFIUklPb5ekVp84pdhtjzw7UlFtntd/K0 0nGXT0ulSE9Q8h1HGOtjunzn7Yi476Co9ZwQPHTAVs1XDyVsNaFnn2JOoWnn0gUvE3XH bPdJC1TQY8HDToweIIgFFJodSHVsnZDiRvlwMY2phjBA+KkPl77sG05JDF1uhQeTXc5m 6xQwLvHq+VGomLFfLZljdt3zQxVm5Uhq2JkOr31nWB7xY3U9EGOf7U4mHpkq/i4+kJKx fHWw== 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; bh=gAzFCRlvprSOoc7mshHe5b6LfERsHz41QaxFuqPDi70=; b=PO3X7P8iLUakF2djgKJp3rC8B9oCpOvhYdaZnC/Im1Quc6sE+Hq5tZelDdrYvmGsst JDikdHKsJVKRGN8ugzB8jF+WmD2H3lYKa+c8pvq4zduIoqEM8c14jG/Yints9a5St88i pdP0dl+Um9amKP24mbgK6gEaV9322bjrx5eoCBXuCjbTR4rWPl+Bxbs1JbOqZBhFyGRt kxZ7UdhD65JdzLD02i2CXyJQjH0JaMAP9iEEYMzl1soMpnkWI0ZcO3VcpDHwcfj1+NL+ SrxLdMSZ7d/ABP8uNeiGDCJMmjMLxmakwr59YaybAP9wU/CbFPCOIl5n4lnUAY4UNE0S 2v7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BgiVQRF5; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 e22si2083140ejr.19.2019.09.26.21.36.46; Thu, 26 Sep 2019 21:37:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=BgiVQRF5; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1726145AbfI0Egk (ORCPT + 99 others); Fri, 27 Sep 2019 00:36:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:59730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbfI0Egk (ORCPT ); Fri, 27 Sep 2019 00:36:40 -0400 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 D1F6321920 for ; Fri, 27 Sep 2019 04:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569558999; bh=HWXGSg8v7PMtX2AtP+Cj10Yp3jFpXmeRJ7sWexKkbRA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BgiVQRF5ok2sLpmM7sYDzoJc4cPQhJZftyNrpCPOx2Gc8HNz0u8iiBrsiuE0G1T7Z B61SfNfq3UnTgXqh8Jb2qLFw1j3d8yTz4nzhVUSHIXvXFc94w88V9Qq02tXLx64yFR IzQpj50mjsfnVgY1+wvAhT7PmFNs//sZuvqJBDXQ= Received: by mail-wm1-f48.google.com with SMTP id 5so5005252wmg.0 for ; Thu, 26 Sep 2019 21:36:38 -0700 (PDT) X-Gm-Message-State: APjAAAVCLW9kQrOc4FFxcgS5/x4ZTMFTbq3xpdIES6lim224VGzpYFRk z5/8sBRd7sScfQaLVknsMv2p7cnRL+9gLJzxlITLsA== X-Received: by 2002:a1c:608b:: with SMTP id u133mr5519478wmb.27.1569558997223; Thu, 26 Sep 2019 21:36:37 -0700 (PDT) MIME-Version: 1.0 References: <20190925161255.1871-1-ard.biesheuvel@linaro.org> <20190925161255.1871-19-ard.biesheuvel@linaro.org> In-Reply-To: From: Andy Lutomirski Date: Thu, 26 Sep 2019 21:36:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 18/18] net: wireguard - switch to crypto API for packet encryption To: Linus Torvalds Cc: Pascal Van Leeuwen , Ard Biesheuvel , Linux Crypto Mailing List , Linux ARM , Herbert Xu , David Miller , Greg KH , "Jason A . Donenfeld" , Samuel Neves , Dan Carpenter , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Will Deacon , Marc Zyngier , Catalin Marinas Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org > On Sep 26, 2019, at 6:38 PM, Linus Torvalds wrote: > > - let the caller know what the state size is and allocate the > synchronous state in its own data structures > > - let the caller just call a static "decrypt_xyz()" function for xyz > decryptrion. > > - if you end up doing it synchronously, that function just returns > "done". No overhead. No extra allocations. No unnecessary stuff. Just > do it, using the buffers provided. End of story. Efficient and simple. > > - BUT. > > - any hardware could have registered itself for "I can do xyz", and > the decrypt_xyz() function would know about those, and *if* it has a > list of accelerators (hopefully sorted by preference etc), it would > try to use them. And if they take the job (they might not - maybe > their queues are full, maybe they don't have room for new keys at the > moment, which might be a separate setup from the queues), the > "decrypt_xyz()" function returns a _cookie_ for that job. It's > probably a pre-allocated one (the hw accelerator might preallocate a > fixed number of in-progress data structures). To really do this right, I think this doesn't go far enough. Suppose I'm trying to implement send() over a VPN very efficiently. I want to do, roughly, this: void __user *buf, etc; if (crypto api thinks async is good) { copy buf to some kernel memory; set up a scatterlist; do it async with this callback; } else { do the crypto synchronously, from *user* memory, straight to kernel memory; (or, if that's too complicated, maybe copy in little chunks to a little stack buffer. setting up a scatterlist is a waste of time.) } I don't know if the network code is structured in a way to make this work easily, and the API would be more complex, but it could be nice and fast.