Linux cryptographic layer development
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] crypto: caam - fix in-place RSA payload DMA mapping
@ 2026-10-20 19:25 Jeff Barnes
  2026-10-20 19:25 ` [RFC PATCH 1/1] " Jeff Barnes
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Barnes @ 2026-10-20 19:25 UTC (permalink / raw)
  To: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem
  Cc: linux-crypto, linux-kernel

Hi,

This RFC fixes a DMA ownership problem in the CAAM RSA driver when the
effective source and destination are the same scatterlist.

rsa_edesc_alloc() currently maps the effective source with DMA_TO_DEVICE
and the destination with DMA_FROM_DEVICE. For an in-place request, this
maps the same scatterlist twice concurrently with different DMA directions.

dma_map_sg() is allowed to modify the scatterlist DMA metadata. On the
arm64/IOMMU system where I reproduced this, the two mappings returned
different DMA addresses. The second mapping replaced the metadata needed
to tear down the first one.

Completion subsequently unmapped the destination and then attempted to
unmap the source using the overwritten scatterlist metadata. This resulted
in ARM-LPAE/IOMMU unmap warnings from the CAAM RSA completion paths.

The user-visible crypto self-test failure included:

  alg: sig: sign test failed: invalid output
  alg: sig: test 1 failed for pkcs1(rsa-caam,sha256): err -22

The warnings were observed through the CAAM RSA public and private
completion paths, rsa_pub_done() and rsa_priv_f_done().

The patch gives an exact effective-head alias a single DMA owner.
CAAM reads and writes the shared payload, so the scatterlist is mapped
once with DMA_BIDIRECTIONAL and unmapped once with the original SG count.
Requests with distinct effective source and destination heads retain the
existing DMA_TO_DEVICE / DMA_FROM_DEVICE mappings.

There is one intentional limitation in this RFC.

For the existing direct hardware representation, a shared mapping
returning one DMA segment is straightforward. A shared mapping returning
multiple DMA segments is not. The logical source and destination may
cover different extents of the shared scatterlist, while the existing
SEC4/PDB bookkeeping uses the mapped source/destination counts to select
and locate those hardware views.

Source analysis found request shapes for which assigning the shared
returned count to both views causes the destination SEC4 table position
to differ from the offset reconstructed by PDB setup. Short-source
public RSA also raises a separate source-view selection issue.

Rather than send a representation known to be incorrect to CAAM, this
RFC unmaps a shared mapping that returns more than one DMA segment and
returns -EOPNOTSUPP before SEC4/PDB construction or job submission.

I would particularly appreciate feedback on two questions:

1. Is a single DMA_BIDIRECTIONAL mapping the preferred ownership model
   for an exact effective source/destination alias?

2. For a shared mapping returning multiple DMA segments, should CAAM
   grow separately bounded source and destination SEC4 views, or should
   such requests instead use a distinct destination, for example through
   a bounce-buffer path?

I tested the patch on an LX2160A arm64 system with CAAM Era 10 behind an
ARM SMMU.

The rsa-caam and pkcs1(rsa-caam,sha256) self-tests passed, and the
certificate-verification RSA selftest completed successfully, with no
recurrence of the original ARM-LPAE/IOMMU unmap warnings.

I also exercised the RFC containment path with a targeted full-width
2048-bit RSA request. The same two-entry scatterlist was supplied as
source and destination, using two separately allocated 128-byte entries.
This reached the multi-segment shared-mapping containment path.

The operation returned -EOPNOTSUPP synchronously, no completion callback
ran, and no CAAM descriptor/job-ring, DMA/IOMMU, WARN, Oops, panic, or
invalid-output error occurred during the test interval. The test module
unloaded cleanly.

There are related RSA DMA fixes under discussion. CAAM work for unaligned
RSA destinations uses a bounce-buffer approach, which may provide one
possible direction for the general multi-segment alias case. Separately,
work on RSA buffers on non-coherent DMA systems identified a cacheline
sharing problem and also demonstrates legitimate in-place RSA requests.

Neither is required by this RFC. This patch is based on current Linus
master and addresses the independent problem of acquiring two streaming
DMA mappings over the same live scatterlist.

Thanks,
Jeff

Jeff Barnes (1):
  crypto: caam - fix in-place RSA payload DMA mapping

 drivers/crypto/caam/caampkc.c | 79 ++++++++++++++++++++++++++++++------
 drivers/crypto/caam/caampkc.h |  3 ++
 2 files changed, 69 insertions(+), 13 deletions(-)

-- 
2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-20 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 19:25 [RFC PATCH 0/1] crypto: caam - fix in-place RSA payload DMA mapping Jeff Barnes
2026-10-20 19:25 ` [RFC PATCH 1/1] " Jeff Barnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox