mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: engine: disable BH during completion
@ 2022-01-27 13:33 Corentin Labbe
  2022-02-05  4:03 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Corentin Labbe @ 2022-01-27 13:33 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel, Corentin Labbe

When doing iperf over ipsec with crypto hardware sun8i-ce, I hit some
spinlock recursion bug.

This is due to crypto/crypto_engine not disabling BH when calling
completion function.

Fixes: 735d37b5424b ("crypto: engine - Introduce the block request crypto engine framework")
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
 crypto/crypto_engine.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
index fb07da9920ee..b3844f6d98a3 100644
--- a/crypto/crypto_engine.c
+++ b/crypto/crypto_engine.c
@@ -7,6 +7,7 @@
  * Author: Baolin Wang <baolin.wang@linaro.org>
  */
 
+#include <linux/bottom_half.h>
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -53,7 +54,9 @@ static void crypto_finalize_request(struct crypto_engine *engine,
 				dev_err(engine->dev, "failed to unprepare request\n");
 		}
 	}
+	local_bh_disable();
 	req->complete(req, err);
+	local_bh_enable();
 
 	kthread_queue_work(engine->kworker, &engine->pump_requests);
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: engine: disable BH during completion
  2022-01-27 13:33 [PATCH] crypto: engine: disable BH during completion Corentin Labbe
@ 2022-02-05  4:03 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2022-02-05  4:03 UTC (permalink / raw)
  To: Corentin Labbe; +Cc: davem, linux-crypto, linux-kernel

On Thu, Jan 27, 2022 at 01:33:32PM +0000, Corentin Labbe wrote:
> When doing iperf over ipsec with crypto hardware sun8i-ce, I hit some
> spinlock recursion bug.
> 
> This is due to crypto/crypto_engine not disabling BH when calling
> completion function.
> 
> Fixes: 735d37b5424b ("crypto: engine - Introduce the block request crypto engine framework")
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
>  crypto/crypto_engine.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
> index fb07da9920ee..b3844f6d98a3 100644
> --- a/crypto/crypto_engine.c
> +++ b/crypto/crypto_engine.c
> @@ -7,6 +7,7 @@
>   * Author: Baolin Wang <baolin.wang@linaro.org>
>   */
>  
> +#include <linux/bottom_half.h>
>  #include <linux/err.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
> @@ -53,7 +54,9 @@ static void crypto_finalize_request(struct crypto_engine *engine,
>  				dev_err(engine->dev, "failed to unprepare request\n");
>  		}
>  	}
> +	local_bh_disable();
>  	req->complete(req, err);
> +	local_bh_enable();

Most other drivers call this function in softirq context.  In
general crypto API callback functions expect to be called in softirq
context.

So I think we should fix the driver to do the bh disable instead.

However, it's probably a good idea to add a check in this spot to
detect drivers that are calling this in the wrong context, e.g.,
lockdep_assert_in_softirq().

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-05  4:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-27 13:33 [PATCH] crypto: engine: disable BH during completion Corentin Labbe
2022-02-05  4:03 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®