[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b3b9f41a-adc3-408f-9fc9-69618c4aa2ba@ti.com>
Date: Fri, 6 Feb 2026 17:07:13 +0530
From: T Pratham <t-pratham@...com>
To: Herbert Xu <herbert@...dor.apana.org.au>
CC: "David S. Miller" <davem@...emloft.net>, Manorit Chawdhry
<m-chawdhry@...com>, Kamlesh Gurudasani <kamlesh@...com>, Shiva Tripathi
<s-tripathi1@...com>, Kavitha Malarvizhi <k-malarvizhi@...com>, "Vishal
Mahaveer" <vishalm@...com>, Praneeth Bajjuri <praneeth@...com>,
<linux-crypto@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v8 1/3] crypto: ti - Add support for AES-CTR in DTHEv2
driver
On 06/02/26 14:23, Herbert Xu wrote:
> On Tue, Jan 20, 2026 at 08:14:06PM +0530, T Pratham wrote:
>>
>> + /*
>> + * CTR mode can operate on any input length, but the hardware
>> + * requires input length to be a multiple of the block size.
>> + * We need to handle the padding in the driver.
>> + */
>> + if (ctx->aes_mode == DTHE_AES_CTR && req->cryptlen % AES_BLOCK_SIZE) {
>> + struct scatterlist *sg;
>> + int i = 0;
>> + unsigned int curr_len = 0;
>> +
>> + len -= req->cryptlen % AES_BLOCK_SIZE;
>> + src_nents = sg_nents_for_len(req->src, len);
>> + dst_nents = sg_nents_for_len(req->dst, len);
>> +
>> + /*
>> + * Need to truncate the src and dst to len, else DMA complains.
>> + * Lengths restored at end
>> + */
>> + for_each_sg(req->src, sg, src_nents - 1, i) {
>> + curr_len += sg->length;
>> + }
>> + curr_len += sg->length;
>> + src_bkup_len = sg->length;
>> + sg->length -= curr_len % AES_BLOCK_SIZE;
>
> Please don't modify the SG lists since they may be used elsewhere.
> There is no harm in mapping a bit more data than what you will
> end up using.
The DMA (at least UDMA in K3 SoCs) sends/receives all the mapped length.
If I have the dst sg mapped with length (len + x) but write len in
crypto hardware, the DMA gets stuck waiting for hardware to send the
extra x len. Similar issue in reverse as well.
Also, FWIW, I'm restoring the len in SG list correctly at the end.
>
> Just truncate the length written to the hardware instead.
>
> Thanks,
--
Regards
T Pratham <t-pratham@...com>
Powered by blists - more mailing lists