From patchwork Wed Jul 5 16:40:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 13302399 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 33981EB64DA for ; Wed, 5 Jul 2023 16:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbjGEQkh (ORCPT ); Wed, 5 Jul 2023 12:40:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbjGEQkd (ORCPT ); Wed, 5 Jul 2023 12:40:33 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F7E10EA; Wed, 5 Jul 2023 09:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688575232; x=1720111232; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R0L33/36rdLS6aViuBmvGQXiDgu8r0FRSWMucXF1m6U=; b=CHO5mBKw1YehsCwEQ/r6QMrERVmfYJH89XKeTVt9iTYXQ3/AhTV+zSt8 ODtCUua++OjVu3IMq7NXWPld0HoNWIWvGmLfbfm9z1odfyoNeIWhbj3tC GZE55B+EUzlshKTULxJeC/5VrnnmMtYj9aYoi/VLndOz+AX1sdw29m0mv 4B0z/P86qkZQkwUrE3hhS21llPT2HPVSh+Iacxs60f/KEMyolNVe5uznO Vw+hIagWXU88IbAqhxv/aEJqZDA7uSOPb/foDO1sflIi9Xh/CBss+60vn Urn+a5C5ivqz1ZcFBDNwZP4vP1ha4mxPG+lm6fWHlJYwbItcCYqVXEO2g Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="362258259" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="362258259" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2023 09:40:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="893241761" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="893241761" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.216]) by orsmga005.jf.intel.com with ESMTP; 05 Jul 2023 09:40:28 -0700 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au, agk@redhat.com, snitzer@kernel.org Cc: linux-crypto@vger.kernel.org, dm-devel@redhat.com, linux-kernel@vger.kernel.org, qat-linux@intel.com, heinzm@redhat.com, meenakshi.aggarwal@nxp.com, ebiggers@kernel.org, horia.geanta@nxp.com, V.Sethi@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, davem@davemloft.net, iuliana.prodan@nxp.com, Giovanni Cabiddu , Fiona Trahe Subject: [PATCH 1/3] dm integrity: do not filter algos with CRYPTO_ALG_ALLOCATES_MEMORY Date: Wed, 5 Jul 2023 17:40:07 +0100 Message-Id: <20230705164009.58351-2-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705164009.58351-1-giovanni.cabiddu@intel.com> References: <20230705164009.58351-1-giovanni.cabiddu@intel.com> MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The flag CRYPTO_ALG_ALLOCATES_MEMORY indicates that an algorithm might allocate memory in the datapath and therefore sleep. Dm-integrity is filtering out implementations of skcipher algorithms that have this flag set. However, in the same function it does allocations with GFP_KERNEL. As dm-integrity is re-entrant and capable of handling sleeps that could occur during allocations with GFP_KERNEL, then it is also capable of using skcipher algorithm implementations that have CRYPTO_ALG_ALLOCATES_MEMORY set. Remove the filtering of skcipher implementations with the flag CRYPTO_ALG_ALLOCATES_MEMORY set. Suggested-by: Herbert Xu Link: https://lore.kernel.org/linux-crypto/ZILvtASXQKLG43y9@gondor.apana.org.au/ Signed-off-by: Giovanni Cabiddu Reviewed-by: Fiona Trahe --- drivers/md/dm-integrity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 31838b13ea54..a1013eff01b4 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -3785,7 +3785,7 @@ static int create_journal(struct dm_integrity_c *ic, char **error) struct journal_completion comp; comp.ic = ic; - ic->journal_crypt = crypto_alloc_skcipher(ic->journal_crypt_alg.alg_string, 0, CRYPTO_ALG_ALLOCATES_MEMORY); + ic->journal_crypt = crypto_alloc_skcipher(ic->journal_crypt_alg.alg_string, 0, 0); if (IS_ERR(ic->journal_crypt)) { *error = "Invalid journal cipher"; r = PTR_ERR(ic->journal_crypt); From patchwork Wed Jul 5 16:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 13302400 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 33E68EB64DA for ; Wed, 5 Jul 2023 16:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbjGEQkj (ORCPT ); Wed, 5 Jul 2023 12:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232634AbjGEQkh (ORCPT ); Wed, 5 Jul 2023 12:40:37 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FF2610EA; Wed, 5 Jul 2023 09:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688575236; x=1720111236; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ORYP0BTPC9UmnZNKGK+aTCKZj4NImzCEscAgvgLWfvs=; b=RXiNreG3+paOmBxsCnkMvf53Q2N0KcC+WPdoNVo6HZ21LY7Bd35VIlQF 7E94E5gGmgaZosxHxs56pktULVtSfMu6BGjExBDS8d31H+vL9UeMRe2oH pjQkoKMnSpmr0WC3jkHt6tDpZRAzMw9RbJavyYDq99isXiam1Est0sXCe UkDZb2leYdzBDSDZq3BK3bpzXy/ZtKped0Fx1k2YYRbSkBO9lEhmD9nN2 LVFlvIoohd+AB41z2cAQOeAoIz+2ovb97j4ghgQPSEqdvu1fWbJykWuVO cJb0z0h7xABLrWzvaRZ+DNM+75mbJfkNLs6O1AcoSo2nTBJ0HaemSukFP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="362258287" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="362258287" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2023 09:40:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="893241766" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="893241766" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.216]) by orsmga005.jf.intel.com with ESMTP; 05 Jul 2023 09:40:32 -0700 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au, agk@redhat.com, snitzer@kernel.org Cc: linux-crypto@vger.kernel.org, dm-devel@redhat.com, linux-kernel@vger.kernel.org, qat-linux@intel.com, heinzm@redhat.com, meenakshi.aggarwal@nxp.com, ebiggers@kernel.org, horia.geanta@nxp.com, V.Sethi@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, davem@davemloft.net, iuliana.prodan@nxp.com, Giovanni Cabiddu , Eric Biggers , Fiona Trahe Subject: [PATCH 2/3] crypto: api - adjust meaning of CRYPTO_ALG_ALLOCATES_MEMORY Date: Wed, 5 Jul 2023 17:40:08 +0100 Message-Id: <20230705164009.58351-3-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705164009.58351-1-giovanni.cabiddu@intel.com> References: <20230705164009.58351-1-giovanni.cabiddu@intel.com> MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The CRYPTO_ALG_ALLOCATES_MEMORY flag doesn't allow to distinguish between implementations which don't allocate memory for scatterlists with 4 or less entries (the typical case for dm-crypt) and those that do. The flag's meaning is adjusted based on the ML discussion below. This patch removes the need to set the flag if the implementation can handle scatterlists up to 4 entries without allocating memory. The documentation is updated accordingly, with an extra clarification regarding sleeping. Suggested-by: Herbert Xu Suggested-by: Eric Biggers Link: https://lore.kernel.org/linux-crypto/20200722072932.GA27544@gondor.apana.org.au/ Link: https://lore.kernel.org/linux-crypto/20230523165503.GA864814@google.com/ Signed-off-by: Giovanni Cabiddu Reviewed-by: Fiona Trahe --- include/linux/crypto.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 31f6fee0c36c..15884790a3d0 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -87,8 +87,13 @@ /* * The algorithm may allocate memory during request processing, i.e. during - * encryption, decryption, or hashing. Users can request an algorithm with this - * flag unset if they can't handle memory allocation failures. + * encryption, decryption, or hashing. Algorithms that do not set this flag will + * guarantee that memory is not allocated during request processing, except in + * the avoidable exception cases described below. + * + * Users can request an algorithm with this flag unset if they can't handle + * memory allocation failures or sleeping during request processing. They should + * also follow the constraints below. * * This flag is currently only implemented for algorithms of type "skcipher", * "aead", "ahash", "shash", and "cipher". Algorithms of other types might not @@ -102,6 +107,9 @@ * - If the data were to be divided into chunks of size * crypto_skcipher_walksize() (with any remainder going at the end), no * chunk can cross a page boundary or a scatterlist element boundary. + * - The input and output scatterlists must have no more than 4 entries. + * If the scatterlists contain more than 4 entries, the algorithm may + * allocate memory. * aead: * - The IV buffer and all scatterlist elements must be aligned to the * algorithm's alignmask. @@ -110,10 +118,16 @@ * - If the plaintext/ciphertext were to be divided into chunks of size * crypto_aead_walksize() (with the remainder going at the end), no chunk * can cross a page boundary or a scatterlist element boundary. + * - The input and output scatterlists must have no more than 4 entries. + * If the scatterlists contain more than 4 entries, the algorithm may + * allocate memory. * ahash: * - The result buffer must be aligned to the algorithm's alignmask. * - crypto_ahash_finup() must not be used unless the algorithm implements * ->finup() natively. + * - The input and output scatterlists must have no more than 4 entries. + * If the scatterlists contain more than 4 entries, the algorithm may + * allocate memory. */ #define CRYPTO_ALG_ALLOCATES_MEMORY 0x00010000 From patchwork Wed Jul 5 16:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 13302401 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 8C848EB64DA for ; Wed, 5 Jul 2023 16:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232938AbjGEQkz (ORCPT ); Wed, 5 Jul 2023 12:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232935AbjGEQkv (ORCPT ); Wed, 5 Jul 2023 12:40:51 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFD4719A4; Wed, 5 Jul 2023 09:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688575240; x=1720111240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OnHnR7sBOISNo6UsoPV0T1BdsFN9+BHptNLTHfPi2RE=; b=TITzjQpTB4L61tK5hfJaurDU/qAJDnmDmTYhk2uIdoCvDRy9uIp1ABel W08Vv/gnNPPJ4xsdYPc0UU0rM1Rm5swqy81zHqbr9lUEXluZrJh9Xpx9Q OkGyRqRjXw2CFivW8puQHB7BJEjvaYXVMBAl5s9/5eP8T3/AqRGeCo0pO GUAeQWeSQT39B5NoKMNRazof15nnafKE/yfwxDDp7Q0BW1pBEDVUAhAp1 eyJkZrYDEU/pYj7RkTlQKD8VxPTs28bnQ7VFfwst/zh/iRHwumh2jJVDu ea04+PC7RdoAvaN93YtOZjZ4M5pcAjAr00eQwrwa+ylt5LKhYAzKIf4gP g==; X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="362258310" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="362258310" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2023 09:40:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10762"; a="893241782" X-IronPort-AV: E=Sophos;i="6.01,183,1684825200"; d="scan'208";a="893241782" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.216]) by orsmga005.jf.intel.com with ESMTP; 05 Jul 2023 09:40:36 -0700 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au, agk@redhat.com, snitzer@kernel.org Cc: linux-crypto@vger.kernel.org, dm-devel@redhat.com, linux-kernel@vger.kernel.org, qat-linux@intel.com, heinzm@redhat.com, meenakshi.aggarwal@nxp.com, ebiggers@kernel.org, horia.geanta@nxp.com, V.Sethi@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, davem@davemloft.net, iuliana.prodan@nxp.com, Giovanni Cabiddu , Fiona Trahe Subject: [PATCH 3/3] crypto: qat - remove CRYPTO_ALG_ALLOCATES_MEMORY flag Date: Wed, 5 Jul 2023 17:40:09 +0100 Message-Id: <20230705164009.58351-4-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705164009.58351-1-giovanni.cabiddu@intel.com> References: <20230705164009.58351-1-giovanni.cabiddu@intel.com> MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Remove the CRYPTO_ALG_ALLOCATES_MEMORY flag from the aead, skcipher and acomp alg structures since the driver does not allocate memory in the request processing for scatterlists with 4 or less entries. This allows the QAT driver to be used by dm-crypt. Signed-off-by: Giovanni Cabiddu Reviewed-by: Fiona Trahe --- drivers/crypto/intel/qat/qat_common/qat_algs.c | 13 ++++++------- drivers/crypto/intel/qat/qat_common/qat_comp_algs.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_algs.c b/drivers/crypto/intel/qat/qat_common/qat_algs.c index 3c4bba4a8779..a7a6ac33052a 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_algs.c +++ b/drivers/crypto/intel/qat/qat_common/qat_algs.c @@ -1278,7 +1278,7 @@ static struct aead_alg qat_aeads[] = { { .cra_name = "authenc(hmac(sha1),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha1", .cra_priority = 4001, - .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .cra_flags = CRYPTO_ALG_ASYNC, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), .cra_module = THIS_MODULE, @@ -1295,7 +1295,7 @@ static struct aead_alg qat_aeads[] = { { .cra_name = "authenc(hmac(sha256),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha256", .cra_priority = 4001, - .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .cra_flags = CRYPTO_ALG_ASYNC, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), .cra_module = THIS_MODULE, @@ -1312,7 +1312,7 @@ static struct aead_alg qat_aeads[] = { { .cra_name = "authenc(hmac(sha512),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha512", .cra_priority = 4001, - .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .cra_flags = CRYPTO_ALG_ASYNC, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx), .cra_module = THIS_MODULE, @@ -1330,7 +1330,7 @@ static struct skcipher_alg qat_skciphers[] = { { .base.cra_name = "cbc(aes)", .base.cra_driver_name = "qat_aes_cbc", .base.cra_priority = 4001, - .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .base.cra_flags = CRYPTO_ALG_ASYNC, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct qat_alg_skcipher_ctx), .base.cra_alignmask = 0, @@ -1348,7 +1348,7 @@ static struct skcipher_alg qat_skciphers[] = { { .base.cra_name = "ctr(aes)", .base.cra_driver_name = "qat_aes_ctr", .base.cra_priority = 4001, - .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .base.cra_flags = CRYPTO_ALG_ASYNC, .base.cra_blocksize = 1, .base.cra_ctxsize = sizeof(struct qat_alg_skcipher_ctx), .base.cra_alignmask = 0, @@ -1366,8 +1366,7 @@ static struct skcipher_alg qat_skciphers[] = { { .base.cra_name = "xts(aes)", .base.cra_driver_name = "qat_aes_xts", .base.cra_priority = 4001, - .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK | - CRYPTO_ALG_ALLOCATES_MEMORY, + .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK, .base.cra_blocksize = AES_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct qat_alg_skcipher_ctx), .base.cra_alignmask = 0, diff --git a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c index b533984906ec..bd1383da1c4a 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c +++ b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c @@ -442,7 +442,7 @@ static struct acomp_alg qat_acomp[] = { { .cra_name = "deflate", .cra_driver_name = "qat_deflate", .cra_priority = 4001, - .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, + .cra_flags = CRYPTO_ALG_ASYNC, .cra_ctxsize = sizeof(struct qat_compression_ctx), .cra_module = THIS_MODULE, },