From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796263682; b=HN6AZjSf2aAdoTa9Ozsb2OGPb4WkRBa4MijxiOep/9j6LswxHa2iIZZJcBPJbBgInhxh QL+Rivw9oTfJnQjgnX4hYp4eUTS9opEcebqcRNarGb5DaPSs7PXqxSaDPMyQYSfUmM/ho MrKz0lHhQ9njRtl0H6d3OpHLrsGCtH8ktjw+J6J4O0uy+YHXGCryMB31w9a7z5+caxqK1 pb08/xTHA7OV20Knx+BXwnkR4pwvDl1wJfk5xPWwA9UdY+NrC/fsP4nKHFDUr7Ub3KJc8 anXKRxje6Y/oaqfHIs2Xfm9WzVYfgfka1D2e0STGO0LMjrIyw4IpmKmiv1dUKiOOZfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796263682; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=c7UU1z8o8F8NwQI8DJ+4pVGEoECemxCq7uM6zIphBCM=; b=Qka3cct63mmHucyH6D1H4EcV71q3Pe8KVZvD3qi0H+EfGOvqjK9jeEXIOxAJyojwk0ii xOcWJKTohcBBnMts+zcjzcNx/REpeUZb7nFcpK6ZhYmJqgaCSiaxQ8Cu9ZGgpcAdVUkQK /WgeqHUi6Kwexkg7OzHYRojS9mWiwoFz2cx2gNw8n71mWShXapRuq1DSN87+7Okzk/JNM YM9eoCMrSkRj7xZeoEPRNcKn9r8o43GFw6D7n0UzH4QgR3aI/Qz1k/PCl8dPvlV8yF5ke 7aLtPQ2dNRBWimEoGbuVP/zjgmyUnXwT+IHur+e0RYEzs36rTxLXSpSmK0GcpcwyAXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yCVclQJ4; arc=none smtp.remote-ip=209.85.214.175 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2968B606A32C for ; Thu, 3 Dec 2026 02:08:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2968B606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yCVclQJ4 Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2f041f88577so75094555ad.1 for ; Wed, 02 Dec 2026 18:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796263681; x=1796868481; darn=vger.kernel.org; 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:content-type; bh=c7UU1z8o8F8NwQI8DJ+4pVGEoECemxCq7uM6zIphBCM=; b=yCVclQJ4M8IptSHomhVXoujJPVWZmpQZLNHmAq7yKj0y8hjHp7J8wwEAu41olrGq6r JRUyxg2wvNmDX3jQRYRqSPyX+aSfNt1rkAtnk2cUh0aS/8VYakpt+L6oVQf874Zl/vs4 ZlldFnyztQuayXm/ldtuuzLCJ6+GNNv7cPJ5TXa0AsEJ/UVFgRbFDMuq9itS3xGydRzJ yIQ9epvJKumeeV4LDVs2LVJLNS71OiPRYTbZD3dj9i6q0+lmzT6E42q+y8FAGtWCyXU9 WWdobgSdLp4iv1VkMLu2k2VMvv8rM3yw5OODYqiglkQ/laA3AIhhhZvuvByl5P8Yqezx 03jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796263681; x=1796868481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=c7UU1z8o8F8NwQI8DJ+4pVGEoECemxCq7uM6zIphBCM=; b=ZmiK6n6UsmHLlu9IGcfLlRLXwns8OldIhIwED/dem3AJSYFaMbF705M0ngyFf+uNP2 BlouU9L8jDcky2BRdrxDLt4wLSAQJNGlkMKXsYwvHInJvumnTzcRvWrb4mpeKacJxo48 9oqtESpXy8tlofP1pxeEwBSuiwdCHGZs7A/vRaGaqYxBc6f7pDOWJaJ5UU7OsWh7WZgY KqINDuDFg5C7FWFKC7dXvd03WLC2OxOJSFkppwDZOFuKd7pv4zRb9ZFuYl/Qse5yUuI+ rx6lqLgv/sv7pOh9Ah4HFxsPyPkyQsiShhgR/MniEpO6E8OQFTd9m2MijGMz0rOYbBnr bVpA== X-Gm-Message-State: APuU4Z/g3N66ZfdIG4S9sTqpUB8HYF3YCrUNDGZWKZD1wzRcvu6rt+xu mOgfxL/OArnS0gNDzHuNa8JQlYn7Y25WqBlZWx8z9zE2/5Xn7ehNByg2mvJbnA== X-Gm-Gg: AZFdTZfHpTtKguDp9IH7m0McVgr/nOxgUwVwd3M5OgGCmMTrAeC8u1XAIgLv/KRmDYl xwDr8X5t93yrVdD2qc6MKCX2pdesnBwdgn2lkm4UJlr6A6MtNW1x7VAUw7a3hqwc7QSKDpADx0M ZxeQdnYV3fRYs1AGiefvOY3u0GHAkLBYTmTgfVdbX2ZmkmKpwFhB29zfxEXx2H1S+ANNRg4KbRg u7eEVeyXbm+rDMdnngSZl1IajjA4R1VPN0zdfgAiWl31D2SV1BQ1StfYPZIKyl2JLsDcGnhfWDf dhNDDA6cvx7n1QptGV/Ucmn5gUSh5hIV+AMLtzXyfCcv5w0iT9GwflaaFXQfmAqxWRdq8kMr+Fv 2VIhsR9bD3Pk3LfziMIYApJwi1dg2EzskaQp9ktNIR7v3zTb5ckJWYaNb2v1/5+E7U0BpaG1JjZ INOceggKj27j8jsso5Yk1ijXmWibhWouHqzh2YoE49HMA1ni4CkqIMbFxLa1Rh9dzpkF0V5ad6o d/A41dacfnt3DOL+zwGkarosGLFth8pmSUyruF/p4aXZ2ewCxNzHPqBEv2dQu1vZ0mhrMo1JpC2 rMnLhxpxHSNs3Bq0aRZ8RIjWQk5eKrxUilm0ZUAcw9vHSyOlIVkxzucmQ4V8pmnTqy1uW9AzIi3 Gi/Bv6QeUYyyTzetbzAZDaPPUu9zxM8UlCcQ4wyHl6zJ0q8BzdDUKg7wTqYxyROt7p/hP4mDjBW xz2Bbkd/7wIyVbup9Hm+F0VyU= X-Received: by 2002:a17:903:3c67:b0:2f1:639d:99d1 with SMTP id d9443c01a7336-2f1639d9a9fmr89092895ad.57.1796263681239; Wed, 02 Dec 2026 18:08:01 -0800 (PST) Received: from ryzen.lan ([2601:644:8000:37f::e34]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f0b58fce71sm157752485ad.45.2026.12.02.18.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 18:08:00 -0800 (PST) From: Rosen Penev To: Srujana Challa , Bharat Bhushan , Herbert Xu , "David S. Miller" , Rosen Penev , Boris Brezillon , Arnaud Ebalard , Russell King , Romain Perier , linux-crypto@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 8/8] crypto: cesa - finish long hashes on the non-TDMA path Date: Wed, 2 Dec 2026 18:07:33 -0800 Message-ID: <20261203020733.260995-9-rosenp@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203020733.260995-1-rosenp@gmail.com> References: <20261203020733.260995-1-rosenp@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On engines without TDMA (Orion), the last request of a hash is finished in mv_cesa_ahash_std_step() either by the engine, when the total length fits the descriptor field (0xffff), or with padding built by the driver. Three things go wrong there: - The hand-made padding is only added inside the branch for the last/unfragmented operations, which is only taken when the total length fits the descriptor field. Hashes of 64 KiB or more are therefore never padded. - When the padding does not fit behind the data, the code keeps len % 64 bytes as the amount to hash and carries 64 - padding length bytes into the cache, rather than hashing the whole blocks and carrying the partial one over to a step that adds the padding. - mv_cesa_ahash_std_process() completes the last request as soon as its source data is used up, so a carried-over block and its padding would never be hashed anyway. Enter the finishing code whenever the data of the last request is used up, convert only last/unfragmented operations to middle/first ones when padding by hand, carry the partial block over properly, and complete the last request only once its final operation has been started. The padding added there is now any length up to a block plus the bit count (CESA_HASH_MAX_PADDING_SIZE), more than the request's block cache it used to be built in, so build it in a buffer of its own. Tested on an Armada 385 (WRT3200ACM) with TDMA disabled in a test build, against the software implementations, with this and the two previous patches: before them, single threaded with lengths up to 140000 bytes, 63% of MD5/SHA1/SHA256 digests were wrong and a 4 thread run hung; after them, none of about 240000 hashes of up to 8192 or 140000 bytes, nor of 26000 operations of mixed cipher and hash load over 4 threads. Fixes: f63601fd616a ("crypto: marvell/cesa - add a new driver for Marvell's CESA") Cc: stable@vger.kernel.org Signed-off-by: Rosen Penev --- drivers/crypto/marvell/cesa/cesa.h | 5 ++++ drivers/crypto/marvell/cesa/hash.c | 46 ++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/marvell/cesa/cesa.h b/drivers/crypto/marvell/cesa/cesa.h index 906d55fb6a3a..71a026f5500e 100644 --- a/drivers/crypto/marvell/cesa/cesa.h +++ b/drivers/crypto/marvell/cesa/cesa.h @@ -202,6 +202,8 @@ #define CESA_SA_SRAM_MSK (2048 - 1) #define CESA_MAX_HASH_BLOCK_SIZE 64 +/* Largest hand-made hash padding: 0x80, zeroes, then the 64-bit length */ +#define CESA_HASH_MAX_PADDING_SIZE (CESA_MAX_HASH_BLOCK_SIZE + 8) #define CESA_HASH_BLOCK_SIZE_MSK (CESA_MAX_HASH_BLOCK_SIZE - 1) /** @@ -585,9 +587,12 @@ struct mv_cesa_skcipher_req { /** * struct mv_cesa_ahash_std_req - standard hash request * @offset: current operation offset + * @final_issued: the last operation of the last request (finalised by the + * engine, or followed by the hand-made padding) has been started */ struct mv_cesa_ahash_std_req { unsigned int offset; + bool final_issued; }; /** diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c index b51315cd01df..d568be38d434 100644 --- a/drivers/crypto/marvell/cesa/hash.c +++ b/drivers/crypto/marvell/cesa/hash.c @@ -174,6 +174,8 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req) struct mv_cesa_engine *engine = creq->base.engine; struct mv_cesa_op_ctx *op; unsigned int new_cache_ptr = 0; + u8 padding[CESA_HASH_MAX_PADDING_SIZE]; + bool final; u32 frag_mode; size_t len; unsigned int digsize; @@ -221,16 +223,17 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req) frag_mode = mv_cesa_get_op_cfg(op) & CESA_SA_DESC_CFG_FRAG_MSK; - if (creq->last_req && sreq->offset == req->nbytes && - creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) { + /* All data of the last request is in SRAM: finish the hash. */ + final = creq->last_req && sreq->offset == req->nbytes; + + if (final && creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) { if (frag_mode == CESA_SA_DESC_CFG_FIRST_FRAG) frag_mode = CESA_SA_DESC_CFG_NOT_FRAG; else if (frag_mode == CESA_SA_DESC_CFG_MID_FRAG) frag_mode = CESA_SA_DESC_CFG_LAST_FRAG; } - if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG || - frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) { + if (final) { if (len && creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) { mv_cesa_set_mac_op_total_len(op, creq->len); @@ -238,8 +241,13 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req) int trailerlen = mv_cesa_ahash_pad_len(creq) + 8; if (len + trailerlen > CESA_SA_SRAM_PAYLOAD_SIZE) { - len &= CESA_HASH_BLOCK_SIZE_MSK; - new_cache_ptr = 64 - trailerlen; + /* + * No room for the padding: hash the whole + * blocks now and carry the partial one over + * to the next step, which adds the padding. + */ + new_cache_ptr = len & CESA_HASH_BLOCK_SIZE_MSK; + len &= ~CESA_HASH_BLOCK_SIZE_MSK; if (engine->pool) memcpy(creq->cache, engine->sram_pool + @@ -252,25 +260,31 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req) len, new_cache_ptr); } else { - i = mv_cesa_ahash_pad_req(creq, creq->cache); + /* Up to a block plus the length: not the cache. */ + i = mv_cesa_ahash_pad_req(creq, padding); if (engine->pool) memcpy(engine->sram_pool + len + CESA_SA_DATA_SRAM_OFFSET, - creq->cache, i); + padding, i); else memcpy_toio(engine->sram + len + CESA_SA_DATA_SRAM_OFFSET, - creq->cache, i); + padding, i); len += i; + sreq->final_issued = true; } if (frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) frag_mode = CESA_SA_DESC_CFG_MID_FRAG; - else + else if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG) frag_mode = CESA_SA_DESC_CFG_FIRST_FRAG; } } + if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG || + frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) + sreq->final_issued = true; + mv_cesa_set_mac_op_frag_len(op, len); mv_cesa_update_op_cfg(op, frag_mode, CESA_SA_DESC_CFG_FRAG_MSK); @@ -299,11 +313,12 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status) struct mv_cesa_ahash_std_req *sreq = &creq->req.std; unsigned int left; - if (creq->last_req) { - if (sreq->offset < (req->nbytes - creq->cache_ptr)) - return -EINPROGRESS; - return 0; - } + /* + * The last request may still hold a partial block carried over from + * the previous step, and always needs its final operation. + */ + if (creq->last_req) + return sreq->final_issued ? 0 : -EINPROGRESS; /* * Less than a block left: keep it in the cache for the next request @@ -331,6 +346,7 @@ static void mv_cesa_ahash_std_prepare(struct ahash_request *req) struct mv_cesa_ahash_std_req *sreq = &creq->req.std; sreq->offset = 0; + sreq->final_issued = false; } static void mv_cesa_ahash_dma_step(struct ahash_request *req) -- 2.56.1