Re: [PATCH v4 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers

From: Sahil Malhotra

Date: Thu Nov 12 2026 - 02:56:22 EST


On Thu, Nov 12, 2026 at 10:02:21AM +1100, Changwei Zou wrote:
> The rsa-caam driver directly DMA-maps the destination buffer supplied by
> the caller via req->dst without checking whether it meets the cacheline
> alignment requirements of DMA-incoherent hardware such as i.MX8.

Hi Changwei,

Thanks for v4. I went through all completion and error paths
(rsa_pub_done, rsa_priv_f_done, akcipher_do_one_req incl. -ENOSPC retry,
akcipher_enqueue_req incl. -EBUSY, the init_fail paths and the
rsa_edesc_alloc() labels): unmap happens before the bounce buffer is
freed and nothing leaks. The v4 bounce_len change is also correct.
A few comments, mostly on structure and the commit message.

[...]

> + req_ctx->bounce_buf = NULL;
> + req_ctx->orig_dst = req->dst;
> + if (req->dst_len > 0) {
[...]
> + sg_init_one(&req_ctx->dst, req_ctx->bounce_buf,
> + bounce_len);
> + req->dst = &req_ctx->dst;

1) Please do not overwrite req->dst. It belongs to the caller and is
visible to it while the request is in flight; it also forces every
exit path (and any future one) to remember to restore it. The driver
already uses req_ctx->fixup_src/fixup_src_len for the same purpose on
the input side. Adding req_ctx->fixup_dst (= req->dst or the bounce sg)
and using it in rsa_edesc_alloc(), set_rsa_*_pdb() and rsa_io_unmap()
would remove orig_dst and the restore logic entirely, and make the
patch smaller.

2) Commit message: on arm64 with CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC,
small unaligned kmalloc buffers are already bounced by the DMA API
(dma_kmalloc_needs_bounce() only looks at the size, not the offset).
Could you state which caller hands in the misaligned dst in the
module-signature path (offset into a larger buffer, stack, ...) and
why the DMA layer does not cover it? That helps judge whether this
belongs in the driver or the caller.

Thanks,
Sahil