Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1413893rwb; Thu, 19 Jan 2023 10:14:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYPW4o6u7r8MJYYN18QQH2k8eGxuFfCbBsalxpdQk2D2+O3F21pD3CV7A4seCr/bPSLVao X-Received: by 2002:a05:6a20:8c29:b0:a9:f48e:aea0 with SMTP id j41-20020a056a208c2900b000a9f48eaea0mr35364922pzh.9.1674152081877; Thu, 19 Jan 2023 10:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674152081; cv=none; d=google.com; s=arc-20160816; b=Rn99ySROsqXRNBDeJiygmr3jkXk1yKAL6x3dWwweribQIBaCGqUekfX+/fAwMGYbiR QVgKLDsKaVUOMw/u3zDd+dL35lHM5Z7Qq8xBCDc0V8bo8L5FiUJW+gvaH9Kls7sDYM40 VxUpCY9CfYc1hUegSGTL0W1pQ7slDFK4VBivAaJDwRpLEWJTLMsWXhyyqRjGf858tg95 UGkWSKuI1WdW2jaE/ga/OdZG/a0464Nfu9Wsk1DlVR2/g2jA10Mrfv1EJHgP5xLGupH4 D6+sOU13O4FFgxuUSBzhBVxEZeI59ngj8bz5AFcDY8YfuKRtZfGkQ9IS65CQOuT+OVGY 5vyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4bF12/qep1PDbFnO6gUHntH+OCUapHjuYPjeXCbRLq0=; b=j/LdsMkrxsdZoyakGNKJrOCMF1tsSwbKmB3RE4I1DqyJZUAZe0AMM01arko+nrOTpW xHHvYABCSmxaOC53DbbFKSr4pwHgASBIf2FKSSiqY7xLep0SKBxI9jW7XqhJ7rwqWTb/ TgncZbMq7gH0B582iml13sN/ml7GKglm063pRpyCQphHA6TmB3GIAMBnwDzuAD31FebA IdLqTsmX9AtrT6V6ugUwLurPvPzJGb7wqJ67zMpDHY3z29NLA4jLo2uE/qz3uMC0k7fC EsE7VmIaYtx7DNZPypNv4d32q7JeoS2xeMTqrWQ1co6IvHslkycAqG3W6Ht5kzT28qNz vFmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Odx7DxEI; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v29-20020a63b95d000000b004d184dbf598si3212932pgo.519.2023.01.19.10.14.21; Thu, 19 Jan 2023 10:14:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Odx7DxEI; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbjASSDw (ORCPT + 99 others); Thu, 19 Jan 2023 13:03:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbjASSDv (ORCPT ); Thu, 19 Jan 2023 13:03:51 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF494EE3 for ; Thu, 19 Jan 2023 10:03:49 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id k16so2196842wms.2 for ; Thu, 19 Jan 2023 10:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4bF12/qep1PDbFnO6gUHntH+OCUapHjuYPjeXCbRLq0=; b=Odx7DxEIHZg8hwb036lS+h52uP+N0Tzhudi68CBDrmtYNk4vhRChvSAU4G/Ef3QKpl DDu4aZrVvOK4k461M5Uaz9yoV7yPZn1lsqiO1sYqS+WH3hmQxk6dPGS6FLJqVz6USbQa IDja8SUPgnIMu53xDiEj/bdsop6E+QJjuAiHNKCmBVG9Vx+vJINg1qzFC/eFsixJrOaj GonQkyr8FlkomBOO6y6mcn4xemD5LY+hDcbWo8KJnXlN/ypB1aqUr9hI4tqjmaybnppx ynSjLVJRnrJNij25tUESpT0bEWbyeOBmtPwKlpx2ew5WD3q728fhYgYFc1pL69J8RdY/ y37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4bF12/qep1PDbFnO6gUHntH+OCUapHjuYPjeXCbRLq0=; b=p4iV6q+CpuWDYUyBfyKtW9jinJRkBOEOprFsrTS0bctpTxGEJF93tGrYEJpqH0YEtz CeH6v0Dbk9S3BxuYyqYRfSKxeCGKOdyt93hKC2dM9Zfy+ANaVIxlsSTs6wFDSTXDmZVP uAsNLApOamfxGXnAS3YFknqEm2PuAINtHmRm2jfixjMprx2B+fxEXSF8cE4s49cR3g9v MA4pSvRB2dgQwjyw74u80HGP26ZU4blgTrezIPjC+54NrCGT+D+Gzs74RMuqW2Hr600H miACJb9mu0RNnB3GEhGkFzLRn4x90aiVKnK5lyQIm/HwtrO72XkJoNE7FCDxd2wVXs65 MQTg== X-Gm-Message-State: AFqh2kqkrKCRDAUyYN2e7x35R8X189IAFE/yX/9+NoXzGTy87AkXaax6 esPsXaNepPnjQtSRcz0n2WnVAA== X-Received: by 2002:a05:600c:1f0a:b0:3db:1200:996e with SMTP id bd10-20020a05600c1f0a00b003db1200996emr6839875wmb.16.1674151427540; Thu, 19 Jan 2023 10:03:47 -0800 (PST) Received: from [10.83.37.24] ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m9-20020a7bca49000000b003d98f92692fsm5382293wml.17.2023.01.19.10.03.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Jan 2023 10:03:47 -0800 (PST) Message-ID: <7c4138b4-e7dd-c9c5-11ac-68be90563cad@arista.com> Date: Thu, 19 Jan 2023 18:03:40 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v4 1/4] crypto: Introduce crypto_pool Content-Language: en-US To: Herbert Xu Cc: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Jakub Kicinski , "David S. Miller" , Andy Lutomirski , Bob Gilligan , Dmitry Safonov <0x7f454c46@gmail.com>, Hideaki YOSHIFUJI , Leonard Crestez , Paolo Abeni , Salam Noureddine , netdev@vger.kernel.org, linux-crypto@vger.kernel.org References: <20230118214111.394416-1-dima@arista.com> <20230118214111.394416-2-dima@arista.com> From: Dmitry Safonov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Herbert, On 1/19/23 09:51, Herbert Xu wrote: > On Wed, Jan 18, 2023 at 09:41:08PM +0000, Dmitry Safonov wrote: >> Introduce a per-CPU pool of async crypto requests that can be used >> in bh-disabled contexts (designed with net RX/TX softirqs as users in >> mind). Allocation can sleep and is a slow-path. >> Initial implementation has only ahash as a backend and a fix-sized array >> of possible algorithms used in parallel. >> >> Signed-off-by: Dmitry Safonov >> --- >> crypto/Kconfig | 3 + >> crypto/Makefile | 1 + >> crypto/crypto_pool.c | 333 ++++++++++++++++++++++++++++++++++++++++++ >> include/crypto/pool.h | 46 ++++++ >> 4 files changed, 383 insertions(+) >> create mode 100644 crypto/crypto_pool.c >> create mode 100644 include/crypto/pool.h > > I'm still nacking this. > > I'm currently working on per-request keys which should render > this unnecessary. With per-request keys you can simply do an > atomic kmalloc when you compute the hash. Adding per-request keys sounds like a real improvement to me. But that is not the same issue I'm addressing here. I'm maybe bad at describing or maybe I just don't see how per-request keys would help. Let me describe the problem I'm solving again and please feel free to correct inline or suggest alternatives. The initial need for crypto_pool comes from TCP-AO implementation that I'm pusing upstream, see RFC5925 that describes the option and the latest version of patch set is in [1]. In that patch set hashing is used in a similar way to TCP-MD5: crypto_alloc_ahash() is a slow-path in setsockopt() and the use of pre-allocated requests in fast path, TX/RX softirqs. For TCP-AO 2 algorithms are "must have" in any compliant implementation, according to RFC5926: HMAC-SHA-1-96 and AES-128-CMAC-96, other algorithms are optional. But having in mind that sha1, as you know, is not secure to collision attacks, some customers prefer to have/use stronger hashes. In other words, TCP-AO implementation needs 2+ hashing algorithms to be used in a similar manner as TCP-MD5 uses MD5 hashing. And than, I look around and I see that the same pattern (slow allocation of crypto request and usage on a fast-path with bh disabled) is used in other places over kernel: - here I convert to crypto_pool seg6_hmac & tcp-md5 - net/ipv4/ah4.c could benefit from it: currently it allocates crypto_alloc_ahash() per every connection, allocating user-specified hash algorithm with ahash = crypto_alloc_ahash(x->aalg->alg_name, 0, 0), which are not shared between each other and it doesn't provide pre-allocated temporary/scratch buffer to calculate hash, so it uses GFP_ATOMIC in ah_alloc_tmp() - net/ipv6/ah6.c is copy'n'paste of the above - net/ipv4/esp4.c and net/ipv6/esp6.c are more-or-less also copy'n'paste with crypto_alloc_aead() instead of crypto_alloc_ahash() - net/mac80211/ - another example of the same pattern, see even the comment in ieee80211_key_alloc() where the keys are allocated and the usage in net/mac80211/{rx,tx}.c with bh-disabled - net/xfrm/xfrm_ipcomp.c has its own manager for different compression algorithms that are used in quite the same fashion. The significant exception is scratch area: it's IPCOMP_SCRATCH_SIZE=65400. So, if it could be shared with other crypto users that do the same pattern (bh-disabled usage), it would save some memory. And those are just fast-grep examples from net/, looking closer it may be possible to find more potential users. So, in crypto_pool.c it's 333 lines where is a manager that let a user share pre-allocated ahash requests [comp, aead, may be added on top] inside bh-disabled section as well as share a temporary/scratch buffer. It will make it possible to remove some if not all custom managers of the very same code pattern, some of which don't even try to share pre-allocated tfms. That's why I see some value in this crypto-pool thing. If you NACK it, the alternative for TCP-AO patches would be to add just another pool into net/ipv4/tcp.c that either copies TCP-MD5 code or re-uses it. I fail to see how your per-request keys patches would provide an API alternative to this patch set. Still, users will have to manage pre-allocated tfms and buffers. I can actually see how your per-request keys would benefit *from* this patch set: it will be much easier to wire per-req keys up to crypto_pool to avoid per-CPU tfm allocation for algorithms you'll add support for. In that case you won't have to patch crypto-pool users. [1]: https://lore.kernel.org/all/20221027204347.529913-1-dima@arista.com/T/#u Thanks, waiting for your input, Dmitry