From: <Tudor.Ambarus@microchip.com> To: <herbert@gondor.apana.org.au> Cc: <Nicolas.Ferre@microchip.com>, <alexandre.belloni@bootlin.com>, <Ludovic.Desroches@microchip.com>, <linux-crypto@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <Tudor.Ambarus@microchip.com> Subject: [PATCH 1/5] crypto: atmel-{aes,sha} - Fix incorrect use of dmaengine_terminate_all() Date: Fri, 13 Dec 2019 09:54:42 +0000 [thread overview] Message-ID: <20191213095423.6687-1-tudor.ambarus@microchip.com> (raw) From: Tudor Ambarus <tudor.ambarus@microchip.com> device_terminate_all() is used to abort all the pending and ongoing transfers on the channel, it should be used just in the error path. Also, dmaengine_terminate_all() is deprecated and one should use dmaengine_terminate_async() or dmaengine_terminate_sync(). The method is not used in atomic context, use dmaengine_terminate_sync(). A secondary aspect of this patch is that it luckily avoids a deadlock between atmel_aes and at_hdmac.c. While in tasklet with the lock held, the dma controller invokes the client callback (dmaengine_terminate_all), which tries to get the same lock. The at_hdmac fix would be to drop the lock before invoking the client callback, a fix on at_hdmac will follow. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> --- drivers/crypto/atmel-aes.c | 32 ++------------------------------ drivers/crypto/atmel-sha.c | 1 - 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index 47b20df3adfc..c3f0e99d24b0 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -857,27 +857,6 @@ static int atmel_aes_dma_transfer_start(struct atmel_aes_dev *dd, return 0; } -static void atmel_aes_dma_transfer_stop(struct atmel_aes_dev *dd, - enum dma_transfer_direction dir) -{ - struct atmel_aes_dma *dma; - - switch (dir) { - case DMA_MEM_TO_DEV: - dma = &dd->src; - break; - - case DMA_DEV_TO_MEM: - dma = &dd->dst; - break; - - default: - return; - } - - dmaengine_terminate_all(dma->chan); -} - static int atmel_aes_dma_start(struct atmel_aes_dev *dd, struct scatterlist *src, struct scatterlist *dst, @@ -936,25 +915,18 @@ static int atmel_aes_dma_start(struct atmel_aes_dev *dd, return -EINPROGRESS; output_transfer_stop: - atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM); + dmaengine_terminate_sync(dd->dst.chan); unmap: atmel_aes_unmap(dd); exit: return atmel_aes_complete(dd, err); } -static void atmel_aes_dma_stop(struct atmel_aes_dev *dd) -{ - atmel_aes_dma_transfer_stop(dd, DMA_MEM_TO_DEV); - atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM); - atmel_aes_unmap(dd); -} - static void atmel_aes_dma_callback(void *data) { struct atmel_aes_dev *dd = data; - atmel_aes_dma_stop(dd); + atmel_aes_unmap(dd); dd->is_async = true; (void)dd->resume(dd); } diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index ebf500153700..7cf4ec9ed93a 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -1429,7 +1429,6 @@ static void atmel_sha_dma_callback2(void *data) struct scatterlist *sg; int nents; - dmaengine_terminate_all(dma->chan); dma_unmap_sg(dd->dev, dma->sg, dma->nents, DMA_TO_DEVICE); sg = dma->sg; -- 2.20.1
WARNING: multiple messages have this Message-ID (diff)
From: <Tudor.Ambarus@microchip.com> To: <herbert@gondor.apana.org.au> Cc: alexandre.belloni@bootlin.com, Tudor.Ambarus@microchip.com, Ludovic.Desroches@microchip.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/5] crypto: atmel-{aes,sha} - Fix incorrect use of dmaengine_terminate_all() Date: Fri, 13 Dec 2019 09:54:42 +0000 [thread overview] Message-ID: <20191213095423.6687-1-tudor.ambarus@microchip.com> (raw) From: Tudor Ambarus <tudor.ambarus@microchip.com> device_terminate_all() is used to abort all the pending and ongoing transfers on the channel, it should be used just in the error path. Also, dmaengine_terminate_all() is deprecated and one should use dmaengine_terminate_async() or dmaengine_terminate_sync(). The method is not used in atomic context, use dmaengine_terminate_sync(). A secondary aspect of this patch is that it luckily avoids a deadlock between atmel_aes and at_hdmac.c. While in tasklet with the lock held, the dma controller invokes the client callback (dmaengine_terminate_all), which tries to get the same lock. The at_hdmac fix would be to drop the lock before invoking the client callback, a fix on at_hdmac will follow. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> --- drivers/crypto/atmel-aes.c | 32 ++------------------------------ drivers/crypto/atmel-sha.c | 1 - 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index 47b20df3adfc..c3f0e99d24b0 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -857,27 +857,6 @@ static int atmel_aes_dma_transfer_start(struct atmel_aes_dev *dd, return 0; } -static void atmel_aes_dma_transfer_stop(struct atmel_aes_dev *dd, - enum dma_transfer_direction dir) -{ - struct atmel_aes_dma *dma; - - switch (dir) { - case DMA_MEM_TO_DEV: - dma = &dd->src; - break; - - case DMA_DEV_TO_MEM: - dma = &dd->dst; - break; - - default: - return; - } - - dmaengine_terminate_all(dma->chan); -} - static int atmel_aes_dma_start(struct atmel_aes_dev *dd, struct scatterlist *src, struct scatterlist *dst, @@ -936,25 +915,18 @@ static int atmel_aes_dma_start(struct atmel_aes_dev *dd, return -EINPROGRESS; output_transfer_stop: - atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM); + dmaengine_terminate_sync(dd->dst.chan); unmap: atmel_aes_unmap(dd); exit: return atmel_aes_complete(dd, err); } -static void atmel_aes_dma_stop(struct atmel_aes_dev *dd) -{ - atmel_aes_dma_transfer_stop(dd, DMA_MEM_TO_DEV); - atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM); - atmel_aes_unmap(dd); -} - static void atmel_aes_dma_callback(void *data) { struct atmel_aes_dev *dd = data; - atmel_aes_dma_stop(dd); + atmel_aes_unmap(dd); dd->is_async = true; (void)dd->resume(dd); } diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index ebf500153700..7cf4ec9ed93a 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -1429,7 +1429,6 @@ static void atmel_sha_dma_callback2(void *data) struct scatterlist *sg; int nents; - dmaengine_terminate_all(dma->chan); dma_unmap_sg(dd->dev, dma->sg, dma->nents, DMA_TO_DEVICE); sg = dma->sg; -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2019-12-13 9:54 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-13 9:54 Tudor.Ambarus [this message] 2019-12-13 9:54 ` [PATCH 1/5] crypto: atmel-{aes,sha} - Fix incorrect use of dmaengine_terminate_all() Tudor.Ambarus 2019-12-13 9:54 ` [PATCH 2/5] crypto: atmel-{aes,sha,tdes} - Drop duplicate init of dma_slave_config.direction Tudor.Ambarus 2019-12-13 9:54 ` Tudor.Ambarus 2019-12-13 9:54 ` [PATCH 3/5] crypto: atmel-{aes,sha,tdes} - Stop passing unused argument in _dma_init() Tudor.Ambarus 2019-12-13 9:54 ` Tudor.Ambarus 2019-12-13 9:54 ` [PATCH 4/5] crypto: atmel-{sha,tdes} - Print warn message even when deferring Tudor.Ambarus 2019-12-13 9:54 ` Tudor.Ambarus 2019-12-13 9:54 ` [PATCH 5/5] crypto: atmel-{aes,tdes} - Update the IV only when the op succeeds Tudor.Ambarus 2019-12-13 9:54 ` [PATCH 5/5] crypto: atmel-{aes, tdes} " Tudor.Ambarus 2019-12-20 7:07 ` [PATCH 1/5] crypto: atmel-{aes,sha} - Fix incorrect use of dmaengine_terminate_all() Herbert Xu 2019-12-20 7:07 ` Herbert Xu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191213095423.6687-1-tudor.ambarus@microchip.com \ --to=tudor.ambarus@microchip.com \ --cc=Ludovic.Desroches@microchip.com \ --cc=Nicolas.Ferre@microchip.com \ --cc=alexandre.belloni@bootlin.com \ --cc=herbert@gondor.apana.org.au \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-crypto@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.