From: T Pratham <t-pratham@ti.com>
To: T Pratham <t-pratham@ti.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Sebin Francis <sebin.francis@ti.com>,
Manorit Chawdhry <m-chawdhry@ti.com>,
Praneeth Bajjuri <praneeth@ti.com>,
Vishal Mahaveer <vishalm@ti.com>, <linux-crypto@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v6 07/15] crypto: ti - Separate padding buffer for src and dst
Date: Wed, 30 Sep 2026 16:55:25 +0530 [thread overview]
Message-ID: <20260930112533.1593952-8-t-pratham@ti.com> (raw)
In-Reply-To: <20260930112533.1593952-1-t-pratham@ti.com>
Separate the padding buffer, which is allocated in the req ctx, for src
and dst scatterlist to avoid any DMA mapping issues when not doing
inline operations. In such cases, the current code was mapping the same
padding buffer twice which might cause issues. Also move them into
differnt groups in __dma_from_device_group_begin/end() to separate the
cache lines for transports of different directions.
Fixes: 35645ca63caa1 ("crypto: ti - Add support for AES-CTR in DTHEv2 driver")
Signed-off-by: T Pratham <t-pratham@ti.com>
---
drivers/crypto/ti/dthev2-aes.c | 29 +++++++++++++++++++----------
drivers/crypto/ti/dthev2-common.h | 14 ++++++++++----
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/drivers/crypto/ti/dthev2-aes.c b/drivers/crypto/ti/dthev2-aes.c
index 5be1bcaeee5ed..83d964e884086 100644
--- a/drivers/crypto/ti/dthev2-aes.c
+++ b/drivers/crypto/ti/dthev2-aes.c
@@ -338,6 +338,9 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
int src_mapped_nents;
int dst_mapped_nents;
+ u8 *src_padding = rctx->src_padding;
+ u8 *dst_padding = rctx->dst_padding;
+
bool diff_dst;
enum dma_data_direction src_dir, dst_dir;
@@ -388,8 +391,8 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
sg_init_table(src, src_nents);
sg = dthe_copy_sg(src, req->src, req->cryptlen);
if (pad_len > 0) {
- memzero_explicit(rctx->padding, AES_BLOCK_SIZE);
- sg_set_buf(sg, rctx->padding, pad_len);
+ memzero_explicit(src_padding, AES_BLOCK_SIZE);
+ sg_set_buf(sg, src_padding, pad_len);
}
if (diff_dst) {
@@ -401,8 +404,10 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
sg_init_table(dst, dst_nents);
sg = dthe_copy_sg(dst, req->dst, req->cryptlen);
- if (pad_len > 0)
- sg_set_buf(sg, rctx->padding, pad_len);
+ if (pad_len > 0) {
+ memzero_explicit(dst_padding, AES_BLOCK_SIZE);
+ sg_set_buf(sg, dst_padding, pad_len);
+ }
} else {
dst = src;
}
@@ -491,8 +496,10 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
dma_unmap_sg(tx_dev, src, src_nents, src_dir);
aes_map_src_err:
- if (ctx->aes_mode == DTHE_AES_CTR && req->cryptlen % AES_BLOCK_SIZE)
- memzero_explicit(rctx->padding, AES_BLOCK_SIZE);
+ if (ctx->aes_mode == DTHE_AES_CTR && req->cryptlen % AES_BLOCK_SIZE) {
+ memzero_explicit(rctx->src_padding, AES_BLOCK_SIZE);
+ memzero_explicit(rctx->dst_padding, AES_BLOCK_SIZE);
+ }
if (diff_dst)
kfree(dst);
@@ -880,9 +887,9 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
int src_mapped_nents = 0;
int dst_mapped_nents = 0;
- u8 *src_assoc_padbuf = rctx->padding;
- u8 *src_crypt_padbuf = rctx->padding + AES_BLOCK_SIZE;
- u8 *dst_crypt_padbuf = rctx->padding + AES_BLOCK_SIZE;
+ u8 *src_assoc_padbuf = rctx->aad_padding;
+ u8 *src_crypt_padbuf = rctx->src_padding;
+ u8 *dst_crypt_padbuf = rctx->dst_padding;
bool diff_dst;
enum dma_data_direction aad_dir, src_dir, dst_dir;
@@ -1125,7 +1132,9 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
kfree(aad_sg);
aead_prep_aad_err:
- memzero_explicit(rctx->padding, 2 * AES_BLOCK_SIZE);
+ memzero_explicit(rctx->aad_padding, AES_BLOCK_SIZE);
+ memzero_explicit(rctx->src_padding, AES_BLOCK_SIZE);
+ memzero_explicit(rctx->dst_padding, AES_BLOCK_SIZE);
if (ret)
ret = dthe_aead_do_fallback(req);
diff --git a/drivers/crypto/ti/dthev2-common.h b/drivers/crypto/ti/dthev2-common.h
index e2600447f217a..f6e02f33ef106 100644
--- a/drivers/crypto/ti/dthev2-common.h
+++ b/drivers/crypto/ti/dthev2-common.h
@@ -109,15 +109,21 @@ struct dthe_tfm_ctx {
/**
* struct dthe_aes_req_ctx - AES engine req ctx struct
* @enc: flag indicating encryption or decryption operation
- * @padding: padding buffer for handling unaligned data
+ * @src_padding: padding buffer for handling unaligned data in src
+ * @aad_padding: padding buffer for handling unaligned data in aad
+ * @dst_padding: padding buffer for handling unaligned data in dst
* @aes_compl: Completion variable for use in manual completion in case of DMA callback failure
* @dev_data: Device data struct pointer
*/
struct dthe_aes_req_ctx {
int enc;
- __dma_from_device_group_begin();
- u8 padding[2 * AES_BLOCK_SIZE];
- __dma_from_device_group_end();
+ __dma_from_device_group_begin(to_device);
+ u8 src_padding[AES_BLOCK_SIZE];
+ u8 aad_padding[AES_BLOCK_SIZE];
+ __dma_from_device_group_end(to_device);
+ __dma_from_device_group_begin(from_device);
+ u8 dst_padding[AES_BLOCK_SIZE];
+ __dma_from_device_group_end(from_device);
struct completion aes_compl;
struct dthe_data *dev_data;
};
--
2.34.1
next prev parent reply other threads:[~2026-09-30 11:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 11:25 [PATCH v6 00/15] Fix several issues in DTHEv2 driver T Pratham
2026-09-30 11:25 ` [PATCH v6 01/15] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() T Pratham
2026-09-30 11:25 ` [PATCH v6 02/15] crypto: ti - Fix spinlock inconsistency in DTHEv2 T Pratham
2026-09-30 11:25 ` [PATCH v6 03/15] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-09-30 11:25 ` [PATCH v6 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
2026-09-30 11:25 ` [PATCH v6 05/15] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-09-30 11:25 ` [PATCH v6 06/15] crypto: ti - Align buffers to cacheline for DMA T Pratham
2026-09-30 11:25 ` T Pratham [this message]
2026-09-30 11:25 ` [PATCH v6 08/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AES T Pratham
2026-09-30 11:25 ` [PATCH v6 09/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AEAD T Pratham
2026-09-30 11:25 ` [PATCH v6 10/15] crypto: ti - Terminate DMA on all error paths in AES to clear descriptors T Pratham
2026-09-30 11:25 ` [PATCH v6 11/15] crypto: ti - Terminate DMA on all error paths in AEAD " T Pratham
2026-09-30 11:25 ` [PATCH v6 12/15] crypto: ti - Do AEAD software fallback on only ENOMEM T Pratham
2026-09-30 11:25 ` [PATCH v6 13/15] crypto: ti - Correct AEAD tag operations against dma cache invalidation T Pratham
2026-09-30 11:25 ` [PATCH v6 14/15] crypto: ti - Change lengths in AES to u64 to avoid potential overflows T Pratham
2026-09-30 11:25 ` [PATCH v6 15/15] crypto: ti - Change lengths in AEAD " T Pratham
2026-09-30 13:03 ` [PATCH v6 00/15] Fix several issues in DTHEv2 driver T Pratham
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=20260930112533.1593952-8-t-pratham@ti.com \
--to=t-pratham@ti.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=praneeth@ti.com \
--cc=sebin.francis@ti.com \
--cc=vishalm@ti.com \
/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
all inboxes | Powered by JetHome®