From patchwork Fri Mar 1 13:29:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 208837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1078833dyb; Fri, 1 Mar 2024 05:33:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7W6hQ4yLXCZwcF1sjS7BsaBK2ybAEVS3HDfg+kZRbMrRSWsyridQ6kiYlYyVwHJyFnXFQ3btXmWcMs29FJ3R08tEbAw== X-Google-Smtp-Source: AGHT+IHCao9gVFAisjbzVD8ZjV8S0aW3rLtpkQjyuToHR+eg9RylPFMunEOFJ/SBXFCsGkIdMphn X-Received: by 2002:a05:6a20:12c4:b0:1a1:2750:4eb3 with SMTP id v4-20020a056a2012c400b001a127504eb3mr1426436pzg.31.1709300024334; Fri, 01 Mar 2024 05:33:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709300024; cv=pass; d=google.com; s=arc-20160816; b=AQF9Zc7bpCDtONQJILz7E9kC4cCpr4Q1BubW0aGZKEIGQiKq/1Keb9Wyj3uE8rFMxY PH9fDQ7FLACX+p0r1UzhkvWa5kmg6zNQeW3LBTmUzvXde9jo0v82L/qS6sUzS/a3/bWF wE1B8ocpgAIyRCqtfECDR5uAMn7LCRH8rpC9a/R8YkhP6MmAwvcPsFHv06o2vezS5G2N OXLR4eCm9bfYTAn2rIGkRsu1jmoLSwR/irgsmHzOeBNOq5xeuDPmpiPZN+GjHWCdKPIs Gtn7YDxwn1jMosougs1VS7K2R50NsuKjVzDS+BdIQmrgr2OCaHuqPOhpe0JQNaS0vgjf CkcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=dQ01oRVGfEJqjYNQJh4GaJxFBVkR+Mts0Li2EykQaT4=; fh=7+QqR+U+m0B5ryyywou1kgMZVOfT/GgVHz0ZH2Lvlxg=; b=DV/4li7Jz+5QMvAcFWJBZ8a61fy6fItxBsKlExYwOulfLhnlSARDe33wo+vLK1ciRt G5qSng3htPfLSvFwR5lgaFnKvhwtZhsOO4XfjbL8cIiKNSP29OO32B9GOM4RumcPae4K eEyWYMhZe7QK4vrlfsesaMIKVxs50OtAvy5YJAwmUZcCZYsMA1j3ewmcEQP8g3G0C4Iw 0CBW4CvjmoXyLQyIx4IE9XBUr1z19puAIA4+4FrV9+hfXE6zT/5QdihwKTHiSr+88lai /ahtZqZHGpGvh+ZVPrqf2tmNqJj5HwWl05Tsy64uUXSPpWzPy7Mb/VjP0F710RSmfU+Z pMfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=MaeG1M5R; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-88477-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88477-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i188-20020a62c1c5000000b006e5675f72fasi3365003pfg.396.2024.03.01.05.33.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:33:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88477-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=MaeG1M5R; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-88477-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88477-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 27364289D2C for ; Fri, 1 Mar 2024 13:33:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEC61745F0; Fri, 1 Mar 2024 13:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="MaeG1M5R" Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1911470CBD; Fri, 1 Mar 2024 13:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709299818; cv=none; b=PYWB98L3rdFIBIpOhSUo0qKMVgmT4oxSLWqhCRqeru7LApryA22/X3Av/nHpQF9x4iF3l+uUx7Jj8goCBK90BtCBsMyekK8UyGq83//czSFM4NsjEHcs3YJ/T9BJg4DvGeaMxYirm2jupRrUv3MqK4vNjOxdVISPY9ThG9ewCwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709299818; c=relaxed/simple; bh=uJiQ4Qi04ti3TESpQApMStDD5cQhyx8n8lxnOOJJxdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qlZ4/DKvgeESQMe1pEzFmUy2cw2cRNh6VGkJxLjwUZxnhIgBo/DwFBXy0aYEsiwHKVWZJSnbxX9KSWjYgU/S1RkTPgKyawUirnyN6keR6YD5KqiEEVoEMnOCLOJK8R6tnTClpX+8QdbY/PlqpUBAQH3Heh4ON8yage55CmunKt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=MaeG1M5R; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 881251200EB; Fri, 1 Mar 2024 16:30:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 881251200EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1709299814; bh=dQ01oRVGfEJqjYNQJh4GaJxFBVkR+Mts0Li2EykQaT4=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=MaeG1M5RB3C5ETXnwOxpdm2KY5Hk9cOXhwAo8Sq8NngzP23pGUVv5x1+Z/ITAgR2G 74lDtm2CfOm7LdNHXpqwkJYOyQz84bNjm4xTcn6+rfnZyd4e/H9T64FGu0qYel5256 vgIq2UHh4LoHAzO/+KI6s4ifAR4eVXlBxVBP37MA6aywYdZYD7jbMuIRrHMqYDthCZ 1rAJ2KOvK0S6YzPBifKtYxmjaWKEY9T7ctqIB5R/8EcpYJMz6ApLKfqpOGSEa6FPJA 6ig9gc3dYUR9vwHlWw/qLodKiWEQHpQhoulpJBMtnpnVFCoaFHkYBNUi09z0FLSeNg TJaxRkJkRxqNw== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 1 Mar 2024 16:30:14 +0300 (MSK) Received: from user-A520M-DS3H.sigma.sbrf.ru (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 1 Mar 2024 16:30:13 +0300 From: Alexey Romanov To: , , , , , , , , , , CC: , , , , , , Alexey Romanov Subject: [PATCH v5 10/21] drivers: crypto: meson: avoid kzalloc in engine thread Date: Fri, 1 Mar 2024 16:29:25 +0300 Message-ID: <20240301132936.621238-11-avromanov@salutedevices.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301132936.621238-1-avromanov@salutedevices.com> References: <20240301132936.621238-1-avromanov@salutedevices.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 183875 [Feb 29 2024] X-KSMG-AntiSpam-Version: 6.1.0.3 X-KSMG-AntiSpam-Envelope-From: avromanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a, {Tracking_from_domain_doesnt_match_to}, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/02/29 19:21:00 #23899999 X-KSMG-AntiVirus-Status: Clean, skipped X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792330981876008941 X-GMAIL-MSGID: 1792330981876008941 It makes no sense to allocate memory via kzalloc, we can use static buffer, speedup data processing and don't think about kfree() calls. Signed-off-by: Alexey Romanov Reviewed-by: Neil Armstrong --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 26 ++++++++------------- drivers/crypto/amlogic/amlogic-gxl.h | 6 ++--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index a71b133a9e9a..8b8f79f08d6e 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -91,7 +91,6 @@ struct cipher_ctx { struct skcipher_request *areq; struct scatterlist *src_sg; struct scatterlist *dst_sg; - void *bkeyiv; unsigned int src_offset; unsigned int dst_offset; @@ -156,8 +155,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) return; if (blockmode == DESC_OPMODE_CBC) { - memcpy(ctx->bkeyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); - ctx->keyiv.len = AES_MAX_KEY_SIZE + ivsize; + memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, ctx->keyiv.len, DMA_TO_DEVICE); } @@ -304,6 +302,7 @@ static int meson_cipher(struct skcipher_request *areq) .dst_sg = areq->dst, .cryptlen = areq->cryptlen, }; + unsigned int ivsize = crypto_skcipher_ivsize(tfm); int err; dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u ctx.flow=%d\n", __func__, @@ -319,16 +318,16 @@ static int meson_cipher(struct skcipher_request *areq) mc->chanlist[rctx->flow].stat_req++; #endif - ctx.bkeyiv = kzalloc(48, GFP_KERNEL | GFP_DMA); - if (!ctx.bkeyiv) - return -ENOMEM; - - memcpy(ctx.bkeyiv, op->key, op->keylen); ctx.keyiv.len = op->keylen; if (ctx.keyiv.len == AES_KEYSIZE_192) ctx.keyiv.len = AES_MAX_KEY_SIZE; - ctx.keyiv.addr = dma_map_single(mc->dev, ctx.bkeyiv, ctx.keyiv.len, + if (algt->blockmode == DESC_OPMODE_CBC) { + memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); + ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; + } + + ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { @@ -366,8 +365,6 @@ static int meson_cipher(struct skcipher_request *areq) meson_unmap_scatterlist(areq, mc); theend: - kfree_sensitive(ctx.bkeyiv); - return err; } @@ -450,7 +447,6 @@ static void meson_cipher_exit(struct crypto_tfm *tfm) { struct meson_cipher_tfm_ctx *op = crypto_tfm_ctx(tfm); - kfree_sensitive(op->key); crypto_free_skcipher(op->fallback_tfm); } @@ -474,11 +470,9 @@ static int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); return -EINVAL; } - kfree_sensitive(op->key); + + memcpy(op->keyiv, key, keylen); op->keylen = keylen; - op->key = kmemdup(key, keylen, GFP_KERNEL | GFP_DMA); - if (!op->key) - return -ENOMEM; return crypto_skcipher_setkey(op->fallback_tfm, key, keylen); } diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index f3455babb52a..dc5218064f99 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -127,15 +127,15 @@ struct meson_cipher_req_ctx { /* * struct meson_cipher_tfm_ctx - context for a skcipher TFM - * @key: pointer to key data + * @keyiv: key data * @keylen: len of the key * @keymode: The keymode(type and size of key) associated with this TFM * @mc: pointer to the private data of driver handling this TFM * @fallback_tfm: pointer to the fallback TFM */ struct meson_cipher_tfm_ctx { - u32 *key; - u32 keylen; + u8 keyiv[AES_MAX_KEY_SIZE + AES_BLOCK_SIZE] ____cacheline_aligned; + u32 keylen ____cacheline_aligned; u32 keymode; struct meson_dev *mc; struct crypto_skcipher *fallback_tfm;