From patchwork Wed Jan 18 21:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 45516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2577284wrn; Wed, 18 Jan 2023 13:43:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsOmpa3KNveyhAmGT2y0nYAVfgUFXsjc4puiEltfLGgKPf36SK+BaeovKEr05ww8VDQ0nCo X-Received: by 2002:a17:906:3515:b0:7c1:1b89:1fe0 with SMTP id r21-20020a170906351500b007c11b891fe0mr8512976eja.65.1674078217757; Wed, 18 Jan 2023 13:43:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674078217; cv=none; d=google.com; s=arc-20160816; b=zpbf2KZLLPecAdkT+kQYIvcc6zD3nhUCjWLqcAUKqaGUCOiz24YnJFZ5LDVQPN+m/c 5QkgU9L5xMqHm6NgWWjdMVOvo6tk6YhPXx0HkB37JFX75lGJ1iP+mSZFaJmj0b5Ai7es WtAqpfjtYUV1vztNrCTdEQqw3JohFceviJQ4enP7zVtBrOjfDacVGXTWX0ujFxHpFeGw +v0yOx3k6P4CicvyxyyGOp7NeWGqw3cztmoZzzGfj/OlpbQd7T9wl6TGyWrTYj1vFSWB rckH5NCNcHFavjUMB4FjLx0PEkuych8LSlHyjPKrprsA/h8uavb3oajaw/Ol52Em5tVo JIHA== 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=FMLRObJikupEwzTrRnh2PGmgjZ9Cqtc3WwiwTSH8KzM=; b=pEgR71TVOUUxLaZYPTrPEWn1k6z78RxU+VaFY+4ySbCGOjrAjSx0wfQjgVF3NwK8ND 2t8meuOzEKUByI7e7O3rRpOuMEYkRXT2Nr61iXC521/3e0Jyo3sdm4swSX0wWU0w/FTE wEzE7M3dEM5+Sp3CSurQa2+Ewyis1sDjLowjos5wrAiRMvCyp/0I5UdqRoJeVxSoXo3n mOE+udQVd0DGF4f+egaAJF5AKQbHHOe1rja1woB3PMg9Ugetjp7pG+dr+8fe8HeCNZ+G JT2MGDdWu2I9ZByojBrCnypPrAYZ1Zx1zCcho9v3X+E/rzGDQNtd/c15qfr0tcJJ9VHP jJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=eCtXeYsP; 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 hp4-20020a1709073e0400b007c106ff40ddsi43779463ejc.631.2023.01.18.13.43.14; Wed, 18 Jan 2023 13:43:37 -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=eCtXeYsP; 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 S231137AbjARVmK (ORCPT + 99 others); Wed, 18 Jan 2023 16:42:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbjARVlt (ORCPT ); Wed, 18 Jan 2023 16:41:49 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F315F63E0C for ; Wed, 18 Jan 2023 13:41:25 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id k8so20846843wrc.9 for ; Wed, 18 Jan 2023 13:41:25 -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=FMLRObJikupEwzTrRnh2PGmgjZ9Cqtc3WwiwTSH8KzM=; b=eCtXeYsP+ADhvJqyR5obWxJN2h47MVmxSPM3WN/yFWVLL7Bofz6ALMqkQ5FmPFSW8x UWaka0KuTIy7rIQGm6zFjHry+P1eL6Sk8lHn9fP+GlFKwmKfj/Q6EGvopu1kINYq/tef zm8zNYOALlS2vhNm+EkXcXVPzdDc/TXwTPpHmjgDI6AlVHBF2UVGGn5IwZJjA1mkQrTd W7/8pHqfbBiiPSMO3n8KjIvPtsQCwLJhGfGrg9lAgqPV+bv5lqOuwfh93c0xePh+Wkpp 2YLAsoMIKNpdfYZLV7cFr9MhZ4e3JlmJFQlcJhphihQuV+4yzmbAlgwjxUanzoyThCaw x8Nw== 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=FMLRObJikupEwzTrRnh2PGmgjZ9Cqtc3WwiwTSH8KzM=; b=aI6PZEt+N2DPN1o6U6SAcc3u5tBOzb31+4HYpxE8VhTR3hThQeeFuGwzJwQbXX4FN9 lI7JRWJ+3Yq0d/UgMuQ2ShgRalKbzsNMIhV/wa/OjkAAAYqrBl55WnJLBkGyzJZbxBbt 6HNJMrt0E6ohXAWOWpx4Yl9/FQoqG1D74JyYpUZl24MWu6zE8EO4mnsS7UR7rAhXzAD1 OZAcCM3D/Y3upvv/ekXji/M1VGJL0KOCbFzmk6bDtjDJ57GLEJh4r2oIBeHbzFCrZ0cc PCZDWTKejMM5U3BJH0MlOxPH+l2/2njWwFJAsnM6vd3rgkmGlnCcV7vK8x0jDyPfFm5l txLg== X-Gm-Message-State: AFqh2krsEIFiGwfUKK8UB0Jub19Zb/wWFgbDk98E6e/XNqKTyXRNznb/ 6P7AKiV2GjyBzuOltwhqYUKMQKXhlYsvXvRM X-Received: by 2002:a5d:5b0e:0:b0:250:22e4:b89e with SMTP id bx14-20020a5d5b0e000000b0025022e4b89emr8426197wrb.65.1674078084270; Wed, 18 Jan 2023 13:41:24 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m5-20020a056000024500b00267bcb1bbe5sm33186349wrz.56.2023.01.18.13.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:41:23 -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 v4 4/4] crypto/Documentation: Add crypto_pool kernel API Date: Wed, 18 Jan 2023 21:41:11 +0000 Message-Id: <20230118214111.394416-5-dima@arista.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118214111.394416-1-dima@arista.com> References: <20230118214111.394416-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?1755398241338317806?= X-GMAIL-MSGID: =?utf-8?q?1755398241338317806?= Signed-off-by: Dmitry Safonov --- Documentation/crypto/crypto_pool.rst | 36 ++++++++++++++++++++++++++++ Documentation/crypto/index.rst | 1 + 2 files changed, 37 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..84abd1f2ee80 --- /dev/null +++ b/Documentation/crypto/crypto_pool.rst @@ -0,0 +1,36 @@ +.. 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 crypto requests on fast paths, potentially in 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_get(). 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_get() and crypto_pool_release() must be called +only for an already existing pool and can be called in atomic contexts. + +crypto_pool_start() 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_end() enables bh back once you've done with your crypto +operation. + +.. kernel-doc:: include/crypto/pool.h + :identifiers: + +.. kernel-doc:: crypto/crypto_pool.c + :identifiers: diff --git a/Documentation/crypto/index.rst b/Documentation/crypto/index.rst index 21338fa92642..3eaf4e964e5b 100644 --- a/Documentation/crypto/index.rst +++ b/Documentation/crypto/index.rst @@ -25,6 +25,7 @@ for cryptographic use cases, as well as programming examples. devel-algos userspace-if crypto_engine + crypto_pool api api-samples descore-readme