From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Srujana Challa <schalla@marvell.com>,
Bharat Bhushan <bbhushan2@marvell.com>,
"David S. Miller" <davem@davemloft.net>,
Rosen Penev <rosenp@gmail.com>,
Arnaud Ebalard <arno@natisbad.org>,
Boris Brezillon <bbrezillon@kernel.org>,
Russell King <rmk+kernel@arm.linux.org.uk>,
Romain Perier <romain.perier@free-electrons.com>,
stable@vger.kernel.org
Subject: [PATCH 8/8] crypto: cesa - finish long hashes on the non-TDMA path
Date: Fri, 27 Nov 2026 20:40:50 -0800 [thread overview]
Message-ID: <20261128044050.722617-9-rosenp@gmail.com> (raw)
In-Reply-To: <20261128044050.722617-1-rosenp@gmail.com>
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.
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 <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/cesa.h | 3 +++
drivers/crypto/marvell/cesa/hash.c | 38 ++++++++++++++++++++----------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/drivers/crypto/marvell/cesa/cesa.h b/drivers/crypto/marvell/cesa/cesa.h
index 906d55fb6a3a..490d7b46cbfc 100644
--- a/drivers/crypto/marvell/cesa/cesa.h
+++ b/drivers/crypto/marvell/cesa/cesa.h
@@ -585,9 +585,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..5e867e688ffa 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -174,6 +174,7 @@ 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;
+ bool final;
u32 frag_mode;
size_t len;
unsigned int digsize;
@@ -221,16 +222,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 +240,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 +
@@ -262,15 +269,20 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
CESA_SA_DATA_SRAM_OFFSET,
creq->cache, 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 +311,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 +344,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
next prev parent reply other threads:[~2026-11-28 4:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
2026-11-28 4:40 ` [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ Rosen Penev
2026-11-28 4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
2026-11-28 4:40 ` [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Rosen Penev
2026-11-28 4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
2026-11-28 4:52 ` sashiko-bot
2026-11-28 4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
2026-11-28 4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
2026-11-28 4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
2026-11-28 4:40 ` Rosen Penev [this message]
2026-11-28 4:52 ` [PATCH 8/8] crypto: cesa - finish long hashes " sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128044050.722617-9-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=arno@natisbad.org \
--cc=bbhushan2@marvell.com \
--cc=bbrezillon@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=romain.perier@free-electrons.com \
--cc=schalla@marvell.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox