Re: [RFC PATCH 1/1] crypto: caam - fix in-place RSA payload DMA mapping

From: Jeff Barnes

Date: Thu Nov 19 2026 - 14:54:39 EST


Hi Herbert,

> Sashiko has some comments on this patch:

Thanks for pointing me to the review, and sorry for the delayed response.
The prepared v2 addresses two concerns, but the short-input SEC4/PDB
accounting concern remains. Here is the disposition of each finding:

1. PVF1: rejection of multi-segment in-place requests

Agreed. The RFC's -EOPNOTSUPP containment is not suitable as the final
fix. V2 removes it. An aligned exact alias retains one bidirectional
mapping only when dma_map_sg() returns a single DMA segment.

If it returns multiple segments, v2 releases that mapping using the
original entry count, then maps the source DMA_TO_DEVICE and a separate
destination bounce buffer DMA_FROM_DEVICE. This follows Sahil's
recommendation and reuses Changwei's destination-bounce infrastructure.

The padding/layout observations also included in PVF1 overlap PVF2
below; I am not claiming those are fixed by destination bouncing.

2. PVF2: short-input padding and PDB source/table selection

The source shows the accounting mismatch described in the review.
The allocator reserves an extra SEC4 entry when diff_size is nonzero,
but edesc->mapped_src_nents does not include that entry. The private
PDB setters select a source S/G table only when that stored count is
greater than one. Their destination-table offset also uses that count.

I checked the unpatched baseline used by Sashiko,
178aff4cf425b3fc51ff09c571fa1bfbc1eb8ea4. It already contains these
allocation/count/selection rules, before applying this RFC. The issue
is therefore not introduced by the shared-mapping change, but it
remains present in the prepared v2 and needs separate treatment.

In particular, fixing the private padded-input view and auditing the
public input-length/table handling must not be conflated with simply
changing payload DMA ownership. I have not hardware-reproduced or
fixed this finding, and do not claim the public-operation tests below
validate private signing or decryption.

3. PVF3: zero-length source passing the RFC's negative-only check

Agreed. V2 patch 1 rejects src_nents <= 0 before payload mapping or
SEC4 construction, returning -EINVAL for zero and propagating negative
extent errors. It applies the same checks to the destination extent.
A zero-length source therefore cannot reach the shared-mapping path
merely because the destination extent is nonempty.

> Please also explain how your patch interacts with the other
> patches on caam:

The prepared v2 is based on both patches of Changwei's v6:

https://lore.kernel.org/linux-crypto/20261114060032.872141-1-changwei.zou@xxxxxxxxxxxxx/

His error-path fix provides the operation-appropriate unmap dispatch.
His alignment fix provides fixup_dst, destination allocation, and
copy-back/free handling. V2 reuses that infrastructure rather than
adding another destination-buffer implementation or modifying req->dst.
The payload is unmapped before destination copy-back.

The ordering is Changwei's two patches, then the separate SG-extent
validation patch, then the in-place DMA ownership patch. The latter also
records req->src == req->dst before leading-zero stripping and forces a
destination bounce if the effective source advances.

A backport of that combination was tested on an arm64 system with CAAM
behind an SMMUv2, a translated IOMMU domain, and DMA-API debugging
enabled, running kernel 6.6.160.4. All 12 RSA-2048 public-operation alias
tests passed, with no DMA-API, ARM-LPAE/IOMMU, or scatterlist-iterator
warnings observed.

Those tests used direct and backlog-enabled submission; they did not
establish that requests entered the backlog, test private operations, or
cover noncoherent/dma-direct hardware.

The test run also included the independent iterator-boundary correction
now submitted separately:

https://lore.kernel.org/linux-crypto/20261119192007.786827-1-jeffbarnes@xxxxxxxxxxxxxxxxxxx/

On the maintenance concern, Sahil has provided substantive review and
offered noncoherent/dma-direct testing. I have copied the CAAM maintainers,
but cannot speak for them regarding ongoing maintenance.

GitHub Copilot assisted with the implementation, regression tests,
source comparison, and drafting this response.

Thanks,
Jeff