From patchwork Mon Jan 16 20:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 643161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5592AC54EBE for ; Mon, 16 Jan 2023 20:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbjAPUPJ (ORCPT ); Mon, 16 Jan 2023 15:15:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbjAPUPI (ORCPT ); Mon, 16 Jan 2023 15:15:08 -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 6CD1E2411D for ; Mon, 16 Jan 2023 12:15:07 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id l8so3661125wms.3 for ; Mon, 16 Jan 2023 12:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BXm2iudaboNNECVraopzZFOlk9fpCOWA8bZYDHmu2JE=; b=kvavdEJklSQPW4BPlF7gQcXgGCOwyILQRmqgdBU1y8dhBXR4ml6UjaJdhchOBcBJ5u E9VNBbVZ2Ayr8lQH19lZqzUiEMqgdb0YH+RTcmyF3QdE0/lhy0guDnv5XXBk9ROz+Xd+ +/tmjvhWo7gB/RfZszrBvV2eO6CSgI3lnZ63nAgR/e8Bj6jcPTWGbshaUP/SpY7mcC12 bthfWKs8TvS0Wno07m7urSj0qt+xdgpUdI/jlCk6APBUArtBLyzaaCGvXe1tKWBByxfB WZpA79LskAtrh8rmT/UScc8kZPB6HQlbTi8uF6qNy/n+tzaueUwYnt8WSQ7EVC+wEgqt X/VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BXm2iudaboNNECVraopzZFOlk9fpCOWA8bZYDHmu2JE=; b=yZhWlFrW35CcY44Op79fz39dCzq1ciXBT9MAQyFkQ49tXqWppeGlie+dRsZNHCtjT0 MooorBITeqlzLL5DEVI6FFp12IZlP4Cxqd/RiGXQS9p9KMpf2/PJ0y7Jj8hlpWQ2YBNh gVU1GRUGkjvy4ZgNlMNXkgOHIlVYfNNItnvmTZrzBagqCkI0hHFJ9LMdqjH+J81CV8dN ilslWz/awpeBBpHEXF2Zz0xMPn5qSwJ6gwRblsNljZlVZIWexSDuj4g8XGTid8H7KXer x5mKyBmCvY+8T8H2TMxZm5xWupOM0YVD8fHZxGRkh4H32R9NaSonBiMI27dAmtrd+rs6 PASw== X-Gm-Message-State: AFqh2kpgwC4GBPpfmO7Al0MF71c36n/pCheEt64UP3Rb/ME6owRdOxPM jx67uy707GmqWitRKzrA7e4X9g== X-Google-Smtp-Source: AMrXdXs11KEVijhi/vnwuIqP0bzhBdA9g37BqRTmAW6ovoxgf5b8jS9ru1OHNtAkjpHG0vlfn4LPkQ== X-Received: by 2002:a7b:c7c5:0:b0:3da:1135:544 with SMTP id z5-20020a7bc7c5000000b003da11350544mr9277172wmk.40.1673900105894; Mon, 16 Jan 2023 12:15:05 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id bh13-20020a05600c3d0d00b003d358beab9dsm34549829wmb.47.2023.01.16.12.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 12:15:05 -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 v3 0/4] net/crypto: Introduce crypto_pool Date: Mon, 16 Jan 2023 20:14:54 +0000 Message-Id: <20230116201458.104260-1-dima@arista.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Changes since v2 [5]: - Fix incorrect rebase of v2: tcp_md5_add_crypto_pool() was called on twsk creation even for sockets without TCP-MD5 key - Documentation title underline length (Reported-by: kernel test robot ) - Migrate crypto_pool_scratch to __rcu, using rcu_dereference*() and rcu_replace_pointer(). As well, I changed local_bh_{en,dis}able() to rcu_read_{,un}lock_bh(). (Addressing Jakub's review) - Correct Documentation/ to use proper kerneldoc style, include it in toc/tree and editor notes (from Jakub's comments) - Avoid cast in crypto_pool_get() (Jakub's review) - Select CRYPTO in Kconfig, not only CRYPTO_POOL (Jakub's reivew) - Remove free_batch[] with synchronize_rcu() in favor of a struct with a flexible array inside + call_rcu() (suggested by Jakub) - Change scratch `size` argument type from (unsigned long) to (size_t) for consistency - Combined crypto_pool_alloc_ahash() and crypto_pool_reserve_scratch(), now the scratch area size is supplied on crypto_pool allocation (suggested by Jakub) - Removed CONFIG_CRYPTO_POOL_DEFAULT_SCRATCH_SIZE - CRYPTO_POOL now is a hidden symbol (Jakub's review) - Simplified __cpool_alloc_ahash() error-paths, adding local variables (suggested by Jakub) - Resurrect a pool waiting to be destroyed if possible (Jakub's review) - Rename _get() => _start(), _put() => _end(), _add() => _get() (suggested by Jakub) Changes since v1 [1]: - Patches went through 3 iterations inside bigger TCP-AO patch set [2], now I'm splitting it apart and sending it once again as a stand-alone patch set to help reviewing it and make it easier to merge. It is second part of that big series, once it merges the next part will be TCP changes to add Authentication Option support (RFC5925), that use API provided by these patches. - Corrected kerneldoc-style comment near crypto_pool_reserve_scratch() (Reported-By: kernel test robot ) - Added short Documentation/ page for crypto_pool API Add crypto_pool - an API for allocating per-CPU array of crypto requests on slow-path (in sleep'able contexts) and for using them on a fast-path, which is RX/TX for net/* users. The design is based on the current implementations of md5sig_pool, which this patch set makes generic by separating it from TCP core, moving it to crypto/ and adding support for other hashing algorithms than MD5. It makes a generic implementation for a common net/ pattern. The initial motivation to have this API is TCP-AO, that's going to use the very same pattern as TCP-MD5, but for multiple hashing algorithms. Previously, I've suggested to add such API on TCP-AO patch submission [3], where Herbert kindly suggested to help with introducing new crypto API. See also discussion and motivation in crypto_pool-v1 [4]. The API will allow: - to reuse per-CPU ahash_request(s) for different users - to allocate only one per-CPU scratch buffer rather than a new one for each user - to have a common API for net/ users that need ahash on RX/TX fast path In this version I've wired up TCP-MD5 and IPv6-SR-HMAC as users. Potentially, xfrm_ipcomp and xfrm_ah can be converted as well. The initial reason for patches would be to have TCP-AO as a user, which would let it share per-CPU crypto_request for any supported hashing algorithm. [1]: https://lore.kernel.org/all/20220726201600.1715505-1-dima@arista.com/ [2]: https://lore.kernel.org/all/20221027204347.529913-1-dima@arista.com/T/#u [3]: http://lkml.kernel.org/r/20211106034334.GA18577@gondor.apana.org.au [4]: https://lore.kernel.org/all/26d5955b-3807-a015-d259-ccc262f665c2@arista.com/T/#u [5]: https://lore.kernel.org/all/20230103184257.118069-1-dima@arista.com/ Cc: Andy Lutomirski Cc: Bob Gilligan Cc: David Ahern Cc: "David S. Miller" Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Eric Dumazet Cc: Herbert Xu Cc: Hideaki YOSHIFUJI Cc: Jakub Kicinski Cc: Leonard Crestez Cc: Paolo Abeni Cc: Salam Noureddine Cc: netdev@vger.kernel.org Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Dmitry Safonov (4): crypto: Introduce crypto_pool crypto/net/tcp: Use crypto_pool for TCP-MD5 crypto/net/ipv6: sr: Switch to using crypto_pool crypto/Documentation: Add crypto_pool kernel API Documentation/crypto/crypto_pool.rst | 36 +++ Documentation/crypto/index.rst | 1 + crypto/Kconfig | 3 + crypto/Makefile | 1 + crypto/crypto_pool.c | 334 +++++++++++++++++++++++++++ include/crypto/pool.h | 46 ++++ include/net/seg6_hmac.h | 7 - include/net/tcp.h | 24 +- net/ipv4/Kconfig | 1 + net/ipv4/tcp.c | 104 ++------- net/ipv4/tcp_ipv4.c | 100 ++++---- net/ipv4/tcp_minisocks.c | 21 +- net/ipv6/Kconfig | 1 + net/ipv6/seg6.c | 3 - net/ipv6/seg6_hmac.c | 207 +++++++---------- net/ipv6/tcp_ipv6.c | 61 +++-- 16 files changed, 635 insertions(+), 315 deletions(-) create mode 100644 Documentation/crypto/crypto_pool.rst create mode 100644 crypto/crypto_pool.c create mode 100644 include/crypto/pool.h base-commit: 5dc4c995db9eb45f6373a956eb1f69460e69e6d4