1 From 3913dbe4b3256ead342572f7aba726a60ab5fd43 Mon Sep 17 00:00:00 2001
2 Message-Id: <3913dbe4b3256ead342572f7aba726a60ab5fd43.1577917078.git.chunkeey@gmail.com>
3 From: Christian Lamparter <chunkeey@gmail.com>
4 Date: Wed, 1 Jan 2020 22:28:28 +0100
5 Subject: [PATCH 1/2] crypto: crypto4xx - reduce memory fragmentation
6 To: linux-crypto@vger.kernel.org
7 Cc: Herbert Xu <herbert@gondor.apana.org.au>
9 With recent kernels (>5.2), the driver fails to probe, as the
10 allocation of the driver's scatter buffer fails with -ENOMEM.
12 This happens in crypto4xx_build_sdr(). Where the driver tries
13 to get 512KiB (=PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD) of
14 continuous memory. This big chunk is by design, since the driver
15 uses this circumstance in the crypto4xx_copy_pkt_to_dst() to
17 "all scatter-buffers are all neatly organized in one big
18 continuous ringbuffer; So scatterwalk_map_and_copy() can be
19 instructed to copy a range of buffers in one go."
21 The PowerPC arch does not have support for DMA_CMA. Hence,
22 this patch reorganizes the order in which the memory
23 allocations are done. Since the driver itself is responsible
24 for some of the issues.
26 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
28 drivers/crypto/amcc/crypto4xx_core.c | 27 +++++++++++++--------------
29 1 file changed, 13 insertions(+), 14 deletions(-)
31 --- a/drivers/crypto/amcc/crypto4xx_core.c
32 +++ b/drivers/crypto/amcc/crypto4xx_core.c
33 @@ -286,7 +286,8 @@ static u32 crypto4xx_build_gdr(struct cr
35 static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
37 - dma_free_coherent(dev->core_dev->device,
39 + dma_free_coherent(dev->core_dev->device,
40 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
41 dev->gdr, dev->gdr_pa);
43 @@ -354,13 +355,6 @@ static u32 crypto4xx_build_sdr(struct cr
47 - /* alloc memory for scatter descriptor ring */
48 - dev->sdr = dma_alloc_coherent(dev->core_dev->device,
49 - sizeof(struct ce_sd) * PPC4XX_NUM_SD,
50 - &dev->sdr_pa, GFP_ATOMIC);
54 dev->scatter_buffer_va =
55 dma_alloc_coherent(dev->core_dev->device,
56 PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
57 @@ -368,6 +362,13 @@ static u32 crypto4xx_build_sdr(struct cr
58 if (!dev->scatter_buffer_va)
61 + /* alloc memory for scatter descriptor ring */
62 + dev->sdr = dma_alloc_coherent(dev->core_dev->device,
63 + sizeof(struct ce_sd) * PPC4XX_NUM_SD,
64 + &dev->sdr_pa, GFP_ATOMIC);
68 for (i = 0; i < PPC4XX_NUM_SD; i++) {
69 dev->sdr[i].ptr = dev->scatter_buffer_pa +
70 PPC4XX_SD_BUFFER_SIZE * i;
71 @@ -1439,16 +1440,15 @@ static int crypto4xx_probe(struct platfo
72 spin_lock_init(&core_dev->lock);
73 INIT_LIST_HEAD(&core_dev->dev->alg_list);
74 ratelimit_default_init(&core_dev->dev->aead_ratelimit);
75 + rc = crypto4xx_build_sdr(core_dev->dev);
78 rc = crypto4xx_build_pdr(core_dev->dev);
83 rc = crypto4xx_build_gdr(core_dev->dev);
87 - rc = crypto4xx_build_sdr(core_dev->dev);
91 /* Init tasklet for bottom half processing */
92 @@ -1493,7 +1493,6 @@ err_iomap:
94 crypto4xx_destroy_sdr(core_dev->dev);
95 crypto4xx_destroy_gdr(core_dev->dev);
97 crypto4xx_destroy_pdr(core_dev->dev);