Skip to content

Commit b7b88b4

Browse files
Bharat Bhushanherbertx
authored andcommitted
crypto: octeontx2 - Fix address alignment issue on ucode loading
octeontx2 crypto driver allocates memory using kmalloc/kzalloc, and uses this memory for dma (does dma_map_single()). It assumes that kmalloc/kzalloc will return 128-byte aligned address. But kmalloc/kzalloc returns 8-byte aligned address after below changes: "9382bc44b5f5 arm64: allow kmalloc() caches aligned to the smaller cache_line_size()" Completion address should be 32-Byte alignment when loading microcode. Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com> Cc: <stable@vger.kernel.org> # v6.5+ Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2157e50 commit b7b88b4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,12 +1491,13 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
14911491
union otx2_cpt_opcode opcode;
14921492
union otx2_cpt_res_s *result;
14931493
union otx2_cpt_inst_s inst;
1494+
dma_addr_t result_baddr;
14941495
dma_addr_t rptr_baddr;
14951496
struct pci_dev *pdev;
1496-
u32 len, compl_rlen;
14971497
int timeout = 10000;
1498+
void *base, *rptr;
14981499
int ret, etype;
1499-
void *rptr;
1500+
u32 len;
15001501

15011502
/*
15021503
* We don't get capabilities if it was already done
@@ -1519,22 +1520,28 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
15191520
if (ret)
15201521
goto delete_grps;
15211522

1522-
compl_rlen = ALIGN(sizeof(union otx2_cpt_res_s), OTX2_CPT_DMA_MINALIGN);
1523-
len = compl_rlen + LOADFVC_RLEN;
1523+
/* Allocate extra memory for "rptr" and "result" pointer alignment */
1524+
len = LOADFVC_RLEN + ARCH_DMA_MINALIGN +
1525+
sizeof(union otx2_cpt_res_s) + OTX2_CPT_RES_ADDR_ALIGN;
15241526

1525-
result = kzalloc(len, GFP_KERNEL);
1526-
if (!result) {
1527+
base = kzalloc(len, GFP_KERNEL);
1528+
if (!base) {
15271529
ret = -ENOMEM;
15281530
goto lf_cleanup;
15291531
}
1530-
rptr_baddr = dma_map_single(&pdev->dev, (void *)result, len,
1531-
DMA_BIDIRECTIONAL);
1532+
1533+
rptr = PTR_ALIGN(base, ARCH_DMA_MINALIGN);
1534+
rptr_baddr = dma_map_single(&pdev->dev, rptr, len, DMA_BIDIRECTIONAL);
15321535
if (dma_mapping_error(&pdev->dev, rptr_baddr)) {
15331536
dev_err(&pdev->dev, "DMA mapping failed\n");
15341537
ret = -EFAULT;
1535-
goto free_result;
1538+
goto free_rptr;
15361539
}
1537-
rptr = (u8 *)result + compl_rlen;
1540+
1541+
result = (union otx2_cpt_res_s *)PTR_ALIGN(rptr + LOADFVC_RLEN,
1542+
OTX2_CPT_RES_ADDR_ALIGN);
1543+
result_baddr = ALIGN(rptr_baddr + LOADFVC_RLEN,
1544+
OTX2_CPT_RES_ADDR_ALIGN);
15381545

15391546
/* Fill in the command */
15401547
opcode.s.major = LOADFVC_MAJOR_OP;
@@ -1546,14 +1553,14 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
15461553
/* 64-bit swap for microcode data reads, not needed for addresses */
15471554
cpu_to_be64s(&iq_cmd.cmd.u);
15481555
iq_cmd.dptr = 0;
1549-
iq_cmd.rptr = rptr_baddr + compl_rlen;
1556+
iq_cmd.rptr = rptr_baddr;
15501557
iq_cmd.cptr.u = 0;
15511558

15521559
for (etype = 1; etype < OTX2_CPT_MAX_ENG_TYPES; etype++) {
15531560
result->s.compcode = OTX2_CPT_COMPLETION_CODE_INIT;
15541561
iq_cmd.cptr.s.grp = otx2_cpt_get_eng_grp(&cptpf->eng_grps,
15551562
etype);
1556-
otx2_cpt_fill_inst(&inst, &iq_cmd, rptr_baddr);
1563+
otx2_cpt_fill_inst(&inst, &iq_cmd, result_baddr);
15571564
lfs->ops->send_cmd(&inst, 1, &cptpf->lfs.lf[0]);
15581565
timeout = 10000;
15591566

@@ -1576,8 +1583,8 @@ int otx2_cpt_discover_eng_capabilities(struct otx2_cptpf_dev *cptpf)
15761583

15771584
error_no_response:
15781585
dma_unmap_single(&pdev->dev, rptr_baddr, len, DMA_BIDIRECTIONAL);
1579-
free_result:
1580-
kfree(result);
1586+
free_rptr:
1587+
kfree(base);
15811588
lf_cleanup:
15821589
otx2_cptlf_shutdown(lfs);
15831590
delete_grps:

0 commit comments

Comments
 (0)