72f8825cb718c859e3bf54ffb91a3df70679d999
[openwrt/staging/jogo.git] / target / linux / apm821xx / patches-5.4 / 111-crypto-crypto4xx-reduce-memory-fragmentation.patch
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>
8
9 With recent kernels (>5.2), the driver fails to probe, as the
10 allocation of the driver's scatter buffer fails with -ENOMEM.
11
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
16 its advantage:
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."
20
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.
25
26 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
27 ---
28 drivers/crypto/amcc/crypto4xx_core.c | 27 +++++++++++++--------------
29 1 file changed, 13 insertions(+), 14 deletions(-)
30
31 diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
32 index 7d6b695c4ab3..3ce5f0a24cbc 100644
33 --- a/drivers/crypto/amcc/crypto4xx_core.c
34 +++ b/drivers/crypto/amcc/crypto4xx_core.c
35 @@ -286,7 +286,8 @@ static u32 crypto4xx_build_gdr(struct crypto4xx_device *dev)
36
37 static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
38 {
39 - dma_free_coherent(dev->core_dev->device,
40 + if (dev->gdr)
41 + dma_free_coherent(dev->core_dev->device,
42 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
43 dev->gdr, dev->gdr_pa);
44 }
45 @@ -354,13 +355,6 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
46 {
47 int i;
48
49 - /* alloc memory for scatter descriptor ring */
50 - dev->sdr = dma_alloc_coherent(dev->core_dev->device,
51 - sizeof(struct ce_sd) * PPC4XX_NUM_SD,
52 - &dev->sdr_pa, GFP_ATOMIC);
53 - if (!dev->sdr)
54 - return -ENOMEM;
55 -
56 dev->scatter_buffer_va =
57 dma_alloc_coherent(dev->core_dev->device,
58 PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
59 @@ -368,6 +362,13 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
60 if (!dev->scatter_buffer_va)
61 return -ENOMEM;
62
63 + /* alloc memory for scatter descriptor ring */
64 + dev->sdr = dma_alloc_coherent(dev->core_dev->device,
65 + sizeof(struct ce_sd) * PPC4XX_NUM_SD,
66 + &dev->sdr_pa, GFP_ATOMIC);
67 + if (!dev->sdr)
68 + return -ENOMEM;
69 +
70 for (i = 0; i < PPC4XX_NUM_SD; i++) {
71 dev->sdr[i].ptr = dev->scatter_buffer_pa +
72 PPC4XX_SD_BUFFER_SIZE * i;
73 @@ -1439,15 +1440,14 @@ static int crypto4xx_probe(struct platform_device *ofdev)
74 spin_lock_init(&core_dev->lock);
75 INIT_LIST_HEAD(&core_dev->dev->alg_list);
76 ratelimit_default_init(&core_dev->dev->aead_ratelimit);
77 + rc = crypto4xx_build_sdr(core_dev->dev);
78 + if (rc)
79 + goto err_build_sdr;
80 rc = crypto4xx_build_pdr(core_dev->dev);
81 if (rc)
82 - goto err_build_pdr;
83 + goto err_build_sdr;
84
85 rc = crypto4xx_build_gdr(core_dev->dev);
86 - if (rc)
87 - goto err_build_pdr;
88 -
89 - rc = crypto4xx_build_sdr(core_dev->dev);
90 if (rc)
91 goto err_build_sdr;
92
93 @@ -1493,7 +1493,6 @@ static int crypto4xx_probe(struct platform_device *ofdev)
94 err_build_sdr:
95 crypto4xx_destroy_sdr(core_dev->dev);
96 crypto4xx_destroy_gdr(core_dev->dev);
97 -err_build_pdr:
98 crypto4xx_destroy_pdr(core_dev->dev);
99 kfree(core_dev->dev);
100 err_alloc_dev:
101 --
102 2.25.0.rc0
103