From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796263682; b=s0haG1WRJ38fsrCxOWBtKJEcJsGKLIlg5276Rhm7qQqS/WAVFTpEwJ5ohRgtbzVxR5pP kq1Bmlc6X/r3Em2pcOI41TLEAYpWMBo0aFOddESahscD4W0w9tE5EybOjryJonRHWO7e6 0e5kkUJL8Tt/I8vlEGU60xPhYx+IaNpjnsxw3bClx5SJ+6LZ24WDy2XmF8QUen0Muucaq VLfJONDSBvrRZfV6EdTK2kGvXNiLST0PPl4z4TQ9ujdys3g1ePk1Ya3GPawp/+Pbea1uK r7OXfRUpAAyrH2eBMXBYWVfCwKwfq3yAWBhpAvhcC5Eg4Cvl+AKaKeBLtUQEfMUppeg== 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-Forwarded-Encrypted: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=Tuqw7EgnCZEl359mRSQg2bCdnlBYauL7UoV3zk0mHepCMCyUvc0ddw3GYWZI0pbC5A1P gk4Qz62/MjZL8Gov4gRulKyF7DAf9slbVrieT6xblA+UCIf1v8icPFwVyu7YxlE0ndyCx jckSqJaf1baqB+nHdRHt9oddqo7iELRqjBZTzeDnJgGR889jCkX/bMYTVJHmSsOHBHZJ3 ZDrttvWu3ucqe36XsqLRdpOhU4TjsqldTspvtx3ZbUZFdc81V/OdpmuMSIM2f0aelInNt 2jIJhUGB5AOE2eFM4YBXXlfJqueaim+7mh/TqyiRQVMpNQGGOxtUcZmnzhpB7S9fdFw== 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.182 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 397DA606A322 for ; Thu, 3 Dec 2026 02:08:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 397DA606A322 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-f182.google.com with SMTP id d9443c01a7336-2f11330e550so34724555ad.0 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=mN0B3zuGnWFI8UDN405ZIprDNDet6IM68p1pwBUj5M22a2JT5xPsqnQYEksQdfpL+8 Eusu6v3i/VIl59ias/FuEiKp5+JHdAuUiQeoA2E2t9NzifdQ09UMQzmRVEy2jlzUAbUb nLuCsL5vSRtMyxpQHjQ4LRAvRYOCbydDJSUs+9656rDpBS7B8uwWgLjXHGCbZsWEVymd vehhglz9bCm53fOAn8NARO6N7XuEBlY7iLGmapx64RbJgzBrBZUKjCtZ9mhQBJkgMpbK z83GqMEndXqu7BjFZjLfQwa12CUQSHOJ/EKHtarIkwi8RSBy3N3Xjbxlyb53JRk4LWOg ZuZQ== X-Forwarded-Encrypted: i=1; AL+hErGCfZWA8/h/m5FeHGKAyXsVidLakNTfL94sVJN5oJZ9mN4OKyMGK78LeT5g5E5Nd9KISyA2hHSVAz/luE4=@vger.kernel.org X-Gm-Message-State: APuU4Z+VmIN2hVYLRRTF1TtdffycDmwYsYFMMXOhVKuf8V+E1pq37h2o +N1NLrAK+FAsdkrnE2GM1/tMEAXLlTaAa2r5f2EX+1J9XUXMxlOmye5l X-Gm-Gg: AZFdTZcsRIjYHgsduWo1RDhs7y+vu6afwbDADOys7yt4tXjzyYLlO+8bBvGIGGVVJTx MNWwxin9yz+Y1tbeqsI0V/MMmjKmjnEfZklQpMI34/UQv/yUpD8QUZtF031kssstY70YaATMtZo XqDZmn5DKaKioyaMtkeiCp0uo7w/sT4/8R/bdTs36EXy9W8OWoId/uQWlht0Sf/Fn1LVxPlOnGX +5JLLSGhu2Ry9NUGKr41u848RmIVIRYqePO98avtKfKd6uRdalFGaLrJXPN18++qxC2zpdPe9T3 /f7vhCqIo3AtBHgfWt2ogivfAJiJNW0QxZidebvwmIBvPG12o02eaps9WB6eooVMHN9VvyWGcoL s9wXYrXFkLsOfECDEoM4APT3tedj1cSahHbvzxMSopQP61Mv/AJNzoFHUtJUsK8h6Fpygr9fQdq 67lTew0Ri+aaU7dSoivUvc6FErm3qOdJ6erzU6nT2Y71qr0JZHiRpSztq+EHMZf6q1QAZZq2U36 XaynUqBNZJmlHIZM+CdtTtzuWwqbyIdl+/RSjvWiJ6EhOo5X7YZLEmoJqhMim/CLDpeT/R4jh9i IdMupAE1M3iDZlXdLjtRCluHa1jMXvh5taZ8OWOjvifErI7TOq4ItTc3try2v7NCrCG/BRF0QJX VTv0aUoFdoJwy8szMInTlgLmLiPbnw+vtyo3aU5xNKxuWPsnHKRIeua0qr0hTBEhodKOFvpKtyo AgTpsV/MYkIa4RwbLQA7Jfd70= 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: linux-crypto@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