Skip to content

Commit dcd9c76

Browse files
horiagherbertx
authored andcommitted
crypto: caam - avoid S/G table fetching for AEAD zero-length output
When enabling IOMMU support, the following issue becomes visible in the AEAD zero-length case. Even though the output sequence length is set to zero, the crypto engine tries to prefetch 4 S/G table entries (since SGF bit is set in SEQ OUT PTR command - which is either generated in SW in case of caam/jr or in HW in case of caam/qi, caam/qi2). The DMA read operation will trigger an IOMMU fault since the address in the SEQ OUT PTR is "dummy" (set to zero / not obtained via DMA API mapping). 1. In case of caam/jr, avoid the IOMMU fault by clearing the SGF bit in SEQ OUT PTR command. 2. In case of caam/qi - setting address, bpid, length to zero for output entry in the compound frame has a special meaning (cf. CAAM RM): "Output frame = Unspecified, Input address = Y. A unspecified frame is indicated by an unused SGT entry (an entry in which the Address, Length, and BPID fields are all zero). SEC obtains output buffers from BMan as prescribed by the preheader." Since no output buffers are needed, modify the preheader by setting (ABS = 1, ADDBUF = 0): -"ABS = 1 means obtain the number of buffers in ADDBUF (0 or 1) from the pool POOL ID" -ADDBUF: "If ABS is set, ADD BUF specifies whether to allocate a buffer or not" 3. In case of caam/qi2, since engine: -does not support FLE[FMT]=2'b11 ("unused" entry) mentioned in DPAA2 RM -requires output entry to be present, even if not used the solution chosen is to leave output frame list entry zeroized. Fixes: 763069b ("crypto: caam - handle zero-length AEAD output") Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a3af113 commit dcd9c76

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎drivers/crypto/caam/caamalg.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ static void init_aead_job(struct aead_request *req,
11061106
if (unlikely(req->src != req->dst)) {
11071107
if (!edesc->mapped_dst_nents) {
11081108
dst_dma = 0;
1109+
out_options = 0;
11091110
} else if (edesc->mapped_dst_nents == 1) {
11101111
dst_dma = sg_dma_address(req->dst);
11111112
out_options = 0;

‎drivers/crypto/caam/caamalg_qi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
11091109
dma_to_qm_sg_one_ext(&fd_sgt[0], qm_sg_dma +
11101110
(1 + !!ivsize) * sizeof(*sg_table),
11111111
out_len, 0);
1112-
} else if (mapped_dst_nents == 1) {
1112+
} else if (mapped_dst_nents <= 1) {
11131113
dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst), out_len,
11141114
0);
11151115
} else {

‎drivers/crypto/caam/caamalg_qi2.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
559559
dpaa2_fl_set_addr(out_fle, qm_sg_dma +
560560
(1 + !!ivsize) * sizeof(*sg_table));
561561
}
562+
} else if (!mapped_dst_nents) {
563+
/*
564+
* crypto engine requires the output entry to be present when
565+
* "frame list" FD is used.
566+
* Since engine does not support FMT=2'b11 (unused entry type),
567+
* leaving out_fle zeroized is the best option.
568+
*/
569+
goto skip_out_fle;
562570
} else if (mapped_dst_nents == 1) {
563571
dpaa2_fl_set_format(out_fle, dpaa2_fl_single);
564572
dpaa2_fl_set_addr(out_fle, sg_dma_address(req->dst));
@@ -570,6 +578,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
570578

571579
dpaa2_fl_set_len(out_fle, out_len);
572580

581+
skip_out_fle:
573582
return edesc;
574583
}
575584

‎drivers/crypto/caam/qi.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "desc_constr.h"
1919

2020
#define PREHDR_RSLS_SHIFT 31
21+
#define PREHDR_ABS BIT(25)
2122

2223
/*
2324
* Use a reasonable backlog of frames (per CPU) as congestion threshold,
@@ -346,6 +347,7 @@ int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc)
346347
*/
347348
drv_ctx->prehdr[0] = cpu_to_caam32((1 << PREHDR_RSLS_SHIFT) |
348349
num_words);
350+
drv_ctx->prehdr[1] = cpu_to_caam32(PREHDR_ABS);
349351
memcpy(drv_ctx->sh_desc, sh_desc, desc_bytes(sh_desc));
350352
dma_sync_single_for_device(qidev, drv_ctx->context_a,
351353
sizeof(drv_ctx->sh_desc) +
@@ -401,6 +403,7 @@ struct caam_drv_ctx *caam_drv_ctx_init(struct device *qidev,
401403
*/
402404
drv_ctx->prehdr[0] = cpu_to_caam32((1 << PREHDR_RSLS_SHIFT) |
403405
num_words);
406+
drv_ctx->prehdr[1] = cpu_to_caam32(PREHDR_ABS);
404407
memcpy(drv_ctx->sh_desc, sh_desc, desc_bytes(sh_desc));
405408
size = sizeof(drv_ctx->prehdr) + sizeof(drv_ctx->sh_desc);
406409
hwdesc = dma_map_single(qidev, drv_ctx->prehdr, size,

0 commit comments

Comments
 (0)