[PATCH v10 00/12] crypto/dmaengine: qce: introduce BAM locking and use DMA for register I/O
From: Bartosz Golaszewski <hidden>
Date: 2025-12-19 10:08:27
Also in:
dmaengine, linux-arm-msm, linux-crypto, linux-doc, lkml
Vinod: I'm sending a v10 with some additional changes and a new patch constifying the DMA descr metatada ops struct. This series has been on the list for quite some time and has been positively reviewed by a couple people. Unless you have a concrete suggestion on how to do it better, I'd like to ask you to consider picking up patches 1-4 into an immutable branch provided to the crypto maintainers. I would appreciate if this series could make v6.20. Currently the QCE crypto driver accesses the crypto engine registers directly via CPU. Trust Zone may perform crypto operations simultaneously resulting in a race condition. To remedy that, let's introduce support for BAM locking/unlocking using DMA descriptor metadata as medium for passing the relevant information from the QCE engine driver to the BAM driver. In the specific case of the BAM DMA this translates to sending command descriptors performing dummy writes with the relevant flags set. The BAM will then lock all other pipes not related to the current pipe group, and keep handling the current pipe only until it sees the the unlock bit. In order for the locking to work correctly, we also need to switch to using DMA for all register I/O. On top of this, the series contains some additional tweaks and refactoring. The goal of this is not to improve the performance but to prepare the driver for supporting decryption into secure buffers in the future. Tested with tcrypt.ko, kcapi and cryptsetup. Shout out to Daniel and Udit from Qualcomm for helping me out with some DMA issues we encountered. Signed-off-by: Bartosz Golaszewski <redacted> Signed-off-by: Bartosz Golaszewski <redacted> --- Changes in v10: - Move DESC_FLAG_(UN)LOCK BIT definitions from patch 2 to 3 - Add a patch constifying the dma engine metadata as the first in the series - Use the VERSION register for dummy lock/unlock writes - Link to v9: https://lore.kernel.org/r/20251128-qcom-qce-cmd-descr-v9-0-9a5f72b89722@linaro.org (local) Changes in v9: - Drop the global, generic LOCK/UNLOCK flags and instead use DMA descriptor metadata ops to pass BAM-specific information from the QCE to the DMA engine - Link to v8: https://lore.kernel.org/r/20251106-qcom-qce-cmd-descr-v8-0-ecddca23ca26@linaro.org (local) Changes in v8: - Rework the command descriptor logic and drop a lot of unneeded code - Use the physical address for BAM command descriptor access, not the mapped DMA address - Fix the problems with iommu faults on newer platforms - Generalize the LOCK/UNLOCK flags in dmaengine and reword the docs and commit messages - Make the BAM locking logic stricter in the DMA engine driver - Add some additional minor QCE driver refactoring changes to the series - Lots of small reworks and tweaks to rebase on current mainline and fix previous issues - Link to v7: https://lore.kernel.org/all/20250311-qce-cmd-descr-v7-0-db613f5d9c9f@linaro.org/ (local) Changes in v7: - remove unused code: writing to multiple registers was not used in v6, neither were the functions for reading registers over BAM DMA- - remove - don't read the SW_VERSION register needlessly in the BAM driver, instead: encode the information on whether the IP supports BAM locking in device match data - shrink code where possible with logic modifications (for instance: change the implementation of qce_write() instead of replacing it everywhere with a new symbol) - remove duplicated error messages - rework commit messages - a lot of shuffling code around for easier review and a more streamlined series - Link to v6: https://lore.kernel.org/all/20250115103004.3350561-1-quic_mdalam@quicinc.com/ (local) Changes in v6: - change "BAM" to "DMA" - Ensured this series is compilable with the current Linux-next tip of the tree (TOT). Changes in v5: - Added DMA_PREP_LOCK and DMA_PREP_UNLOCK flag support in separate patch - Removed DMA_PREP_LOCK & DMA_PREP_UNLOCK flag - Added FIELD_GET and GENMASK macro to extract major and minor version Changes in v4: - Added feature description and test hardware with test command - Fixed patch version numbering - Dropped dt-binding patch - Dropped device tree changes - Added BAM_SW_VERSION register read - Handled the error path for the api dma_map_resource() in probe - updated the commit messages for batter redability - Squash the change where qce_bam_acquire_lock() and qce_bam_release_lock() api got introduce to the change where the lock/unlock flag get introced - changed cover letter subject heading to "dmaengine: qcom: bam_dma: add cmd descriptor support" - Added the very initial post for BAM lock/unlock patch link as v1 to track this feature Changes in v3: - https://lore.kernel.org/lkml/183d4f5e-e00a-8ef6-a589-f5704bc83d4a@quicinc.com/ (local) - Addressed all the comments from v2 - Added the dt-binding - Fix alignment issue - Removed type casting from qce_write_reg_dma() and qce_read_reg_dma() - Removed qce_bam_txn = dma->qce_bam_txn; line from qce_alloc_bam_txn() api and directly returning dma->qce_bam_txn Changes in v2: - https://lore.kernel.org/lkml/20231214114239.2635325-1-quic_mdalam@quicinc.com/ (local) - Initial set of patches for cmd descriptor support - Add client driver to use BAM lock/unlock feature - Added register read/write via BAM in QCE Crypto driver to use BAM lock/unlock feature --- Bartosz Golaszewski (12): dmaengine: constify struct dma_descriptor_metadata_ops dmaengine: qcom: bam_dma: Extend the driver's device match data dmaengine: qcom: bam_dma: Add bam_pipe_lock flag support dmaengine: qcom: bam_dma: implement support for BAM locking crypto: qce - Include algapi.h in the core.h header crypto: qce - Remove unused ignore_buf crypto: qce - Simplify arguments of devm_qce_dma_request() crypto: qce - Use existing devres APIs in devm_qce_dma_request() crypto: qce - Map crypto memory for DMA crypto: qce - Add BAM DMA support for crypto register I/O crypto: qce - Add support for BAM locking crypto: qce - Switch to using BAM DMA for crypto I/O drivers/crypto/qce/aead.c | 10 +++ drivers/crypto/qce/common.c | 39 ++++++--- drivers/crypto/qce/core.c | 28 ++++++- drivers/crypto/qce/core.h | 11 +++ drivers/crypto/qce/dma.c | 174 +++++++++++++++++++++++++++++++++------ drivers/crypto/qce/dma.h | 15 +++- drivers/crypto/qce/sha.c | 8 ++ drivers/crypto/qce/skcipher.c | 7 ++ drivers/dma/qcom/bam_dma.c | 92 +++++++++++++++++++-- drivers/dma/ti/k3-udma.c | 2 +- drivers/dma/xilinx/xilinx_dma.c | 2 +- include/linux/dma/qcom_bam_dma.h | 12 +++ include/linux/dmaengine.h | 2 +- 13 files changed, 347 insertions(+), 55 deletions(-) --- base-commit: c138e425266a3f8fc801c82793a7084dfbc069b6 change-id: 20251103-qcom-qce-cmd-descr-c5e9b11fe609 Best regards, -- Bartosz Golaszewski [off-list ref]