From patchwork Tue Jan 3 18:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 38597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4766180wrt; Tue, 3 Jan 2023 10:48:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXttn1P9ouPnH1UU8G6LotdXBx/Z2o4ZuhCZ7TfaDKWxsGC3qSCCKkuRaFBCX7J8WeNEYpVo X-Received: by 2002:a17:906:7188:b0:7c0:f117:6990 with SMTP id h8-20020a170906718800b007c0f1176990mr38937861ejk.41.1672771703306; Tue, 03 Jan 2023 10:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672771703; cv=none; d=google.com; s=arc-20160816; b=PZQO+2yaMmlPmTPr6wUNkO1w1K4Vjpay23hKin1rZWz/vrHE0Og5KCKAdHsdHMKjzJ JuqqYphiqljpHbWKHlwhgdCrP3iwCkatEgwB8s+4u+VZYBAn6Zc0VTFdIR+G1j0hvkQB gbVJg7/Q46swAI+SBf4SK3lds3Md908kD6hu48SDQ3eeje50qg8oP0JRZ6+R6azLPiPF LmPXeG0DQU74nGurOhFxQy/vp7D17dwyItYsdwatz0aEIVuwU+UgMe82Zyt5OPdDHIOJ Hmz6JXi3onULEQ23pI3msGukT1wu+vvWVuzvs2iwcIUsxUbJDSSgVsa+Jz3IXFOGAoFr /jsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mCJ7npxHWqpq76xLkWO4j8PK4QmIgUKzcUbzkkrjhHk=; b=HXUrtgWeRVlpCD8+52fOBciE/mSGQfD/nch0mihNVV55UNoIIaLaL3Gx+P65Kuw3ME WIuH6cySLaxR5y7KNUnbiu3SKBMwIQ1FGm7Mn98d4982SsEhXBMSO82Njgy3itRFPKxs RIjNCw3330pA5UVWUvAMIEYnBF/0RGB9kKXC03wMZLfnUDZib42qgiV8id3MHnnvo1Ao RL+2uK+Zx+uI+4ElarPMkVxw5h6nYDHK3lGa28Qo67Ok6TcQCIou1gYR5UZhd+AdoBrE gVH2lYsjwOsKCXK8GatZsv9dUiljtIXF4bq8UuaoUSNgzhCZqgbofwJZFbRIBpud2N6k YLpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=CZ5qHYLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr7-20020a170907720700b0078c4a772ea7si28669614ejc.11.2023.01.03.10.47.59; Tue, 03 Jan 2023 10:48:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=CZ5qHYLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238565AbjACSqP (ORCPT + 99 others); Tue, 3 Jan 2023 13:46:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231240AbjACSpA (ORCPT ); Tue, 3 Jan 2023 13:45:00 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A93115819 for ; Tue, 3 Jan 2023 10:43:12 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m3so14644995wmq.0 for ; Tue, 03 Jan 2023 10:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mCJ7npxHWqpq76xLkWO4j8PK4QmIgUKzcUbzkkrjhHk=; b=CZ5qHYLwlLPQI0PG3wJmLeJmMjKX0fENp37n8nEwoXnjIKGMPeZs6j6FtyOBT6Yp5J 7KgQcqLS3n/tSclWR5Iew/zedibQuNm8CFGB1BLQ/G35Vkng58i/RBKR6P04gmY9bDBU OAbSlnzVH2PjtmHk9m5csZGnCiVfOu9zyD68rt6hrYFzWAaBG1CKSLsxPlvVFk83Exft G9mrsd04Tnt7S3nYb5O1wCqG68BANgvT1EoiN1b/BXRpP5KIB1jmA5SQWCGKTy5rAvbJ HU0a6kiFN1iXZGm2yo/+yeunkHFQxgsBMKPs5l+9vqAzTGamfTJ72LYB/QUwHuMii40r LfSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mCJ7npxHWqpq76xLkWO4j8PK4QmIgUKzcUbzkkrjhHk=; b=iyIxTKx2TDfscWwqnKaPIc0smkKbfNG4GLhig2o6hlU+MSGlU8V5/NVuAKtDXEoMsV I2D48NcAjwjloAVhRKXmtegw/9rX+BOGHnNtAezq438YUtXcFIcApuNNS214+7LcqD7M Hzw19Mdc+jun+m7VIe8+deuxy8TmNHYO5cFbEFZ1zAtCyaEpTejZv/TqFMzceBsUC6jN MqEfiREvJshmdzp1E2kslgRm9q3rlqXqoiSah6sPVcB1oDAMm5VJelRcrktMG9KGOPJH TEUBeVAuSy4ut4O5hGtzXS4iM4dIa5HRtAORjXIPJ6V+qQ7kQsWbUWordqmHiCGq/iBL pYew== X-Gm-Message-State: AFqh2kr6V0UxK5iSvnKeKu9naxAU7b5yGED09j2OkZ5811hNZeZUcuio yE/+GX+eRl4MSaTpB3h+/f5p1qBYjausxEBD X-Received: by 2002:a05:600c:4d21:b0:3d2:2a72:2573 with SMTP id u33-20020a05600c4d2100b003d22a722573mr32110883wmp.11.1672771390924; Tue, 03 Jan 2023 10:43:10 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id i18-20020a5d5232000000b0028e55b44a99sm13811578wra.17.2023.01.03.10.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 10:43:10 -0800 (PST) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Herbert Xu , Jakub Kicinski , "David S. Miller" Cc: Dmitry Safonov , 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 Subject: [PATCH v2 5/5] crypto/Documentation: Add crypto_pool kernel API Date: Tue, 3 Jan 2023 18:42:57 +0000 Message-Id: <20230103184257.118069-6-dima@arista.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230103184257.118069-1-dima@arista.com> References: <20230103184257.118069-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754028261478151929?= X-GMAIL-MSGID: =?utf-8?q?1754028261478151929?= Signed-off-by: Dmitry Safonov --- Documentation/crypto/crypto_pool.rst | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/crypto/crypto_pool.rst diff --git a/Documentation/crypto/crypto_pool.rst b/Documentation/crypto/crypto_pool.rst new file mode 100644 index 000000000000..4b8443171421 --- /dev/null +++ b/Documentation/crypto/crypto_pool.rst @@ -0,0 +1,33 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Per-CPU pool of crypto requests +============= + +Overview +-------- +The crypto pool API manages pre-allocated per-CPU pool of crypto requests, +providing ability to use async crypto requests on fast paths, potentially +on atomic contexts. The allocation and initialization of the requests should +be done before their usage as it's slow-path and may sleep. + +Order of operations +------------------- +You are required to allocate a new pool prior using it and manage its lifetime. +You can allocate a per-CPU pool of ahash requests by ``crypto_pool_alloc_ahash()``. +It will give you a pool id that you can use further on fast-path for hashing. +You can increase the reference counter for an allocated pool via +``crypto_pool_add()``. Decrease the reference counter by ``crypto_pool_release()``. +When the refcounter hits zero, the pool is scheduled for destruction and you +can't use the corresponding crypto pool id anymore. +Note that ``crypto_pool_add()`` and ``crypto_pool_release()`` must be called +only for an already existing pool and can be called in atomic contexts. + +``crypto_pool_get()`` disables bh and returns you back ``struct crypto_pool *``, +which is a generic type for different crypto requests and has ``scratch`` area +that can be used as a temporary buffer for your operation. + +``crypto_pool_put()`` enables bh back once you've done with your crypto +operation. + +If you need to pre-allocate a bigger per-CPU ``scratch`` area for you requests, +you can use ``crypto_pool_reserve_scratch()``.