Skip to contentSkip to conversation

crypto: completion should be ran with BH disabled

PATCH In review Corentin Labbe 2 participants 7 messages Feb 21, 2022 – Mar 2, 2022

Subsystems (7)
lore
Share & tools
lore

Corentin Labbe

author maintainer
#0 lore raw

cover crypto: completion should be ran with BH disabled

Hello

This is the follow up of https://lore.kernel.org/lkml/Yd1SIHUNdLIvKhzz@Red/
and https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/
This serie fix all drivers which do not call completion with BH disabled
and add the check in crypto/engine asked by Herbert.
I have verified that this check does not generate warnings on all other crypto
hardware I got (omap, ccree, rockchip)

Regards

Corentin Labbe (5):
crypto: sun8i-ss: call finalize with bh disabled
crypto: sun8i-ce: call finalize with bh disabled
crypto: amlogic: call finalize with bh disabled
crypto: gemini: call finalize with bh disabled
crypto: engine: check if BH is disabled during completion

 crypto/crypto_engine.c                              | 1 +
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c   | 3 +++
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c   | 3 +++
 drivers/crypto/amlogic/amlogic-gxl-cipher.c         | 2 ++
 drivers/crypto/gemini/sl3516-ce-cipher.c            | 2 ++
 7 files changed, 17 insertions(+)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/5 crypto: sun8i-ss: call finalize with bh disabled

Doing ipsec produces a spinlock recursion warning.
This is due to not disabling BH during crypto completion function.

Fixes f08fcced6d00 ("crypto: allwinner - Add sun8i-ss cryptographic offloader")
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c   | 3 +++
 2 files changed, 6 insertions(+)
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +3 -0
index 9ef1c85c4aaa..554e400d41ca 100644
@@ -11,6 +11,7 @@
  * You could find a link for the datasheet in Documentation/arm/sunxi.rst
  */
 
+#include <linux/bottom_half.h>
 #include <linux/crypto.h>
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
@@ -274,7 +275,9 @@ static int sun8i_ss_handle_cipher_request(struct crypto_engine *engine, void *ar
 	struct skcipher_request *breq = container_of(areq, struct skcipher_request, base);
 
 	err = sun8i_ss_cipher(breq);
+	local_bh_disable();
 	crypto_finalize_skcipher_request(engine, breq, err);
+	local_bh_enable();
 
 	return 0;
 }
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +3 -0
index d8c333fe5eb2..0c2ca296bede 100644
@@ -9,6 +9,7 @@
  *
  * You could find the datasheet in Documentation/arm/sunxi.rst
  */
+#include <linux/bottom_half.h>
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/scatterlist.h>
@@ -633,6 +634,8 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 
 	memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
 theend:
+	local_bh_disable();
 	crypto_finalize_hash_request(engine, breq, err);
+	local_bh_enable();
 	return 0;
 }
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/5 crypto: sun8i-ce: call finalize with bh disabled

In reply to Corentin Labbe

Doing ipsec produces a spinlock recursion warning.
This is due to not disabling BH during crypto completion function.

Fixes 06f751b61329 ("crypto: allwinner - Add sun8i-ce Crypto Engine")
---
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c   | 3 +++
 2 files changed, 6 insertions(+)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +3 -0
index 7cc496c03084..0b1ce58bdeb9 100644
@@ -11,6 +11,7 @@
  * You could find a link for the datasheet in Documentation/arm/sunxi.rst
  */
 
+#include <linux/bottom_half.h>
 #include <linux/crypto.h>
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
@@ -272,7 +273,9 @@ static int sun8i_ce_cipher_run(struct crypto_engine *engine, void *areq)
 
 	flow = rctx->flow;
 	err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(breq->base.tfm));
+	local_bh_disable();
 	crypto_finalize_skcipher_request(engine, breq, err);
+	local_bh_enable();
 	return 0;
 }
 
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +3 -0
index fd7f1db863d9..5b6c51b78dde 100644
@@ -9,6 +9,7 @@
  *
  * You could find the datasheet in Documentation/arm/sunxi.rst
  */
+#include <linux/bottom_half.h>
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/scatterlist.h>
@@ -472,6 +473,8 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
 theend:
 	kfree(buf);
 	kfree(result);
+	local_bh_disable();
 	crypto_finalize_hash_request(engine, breq, err);
+	local_bh_enable();
 	return 0;
 }
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/5 crypto: amlogic: call finalize with bh disabled

In reply to Corentin Labbe

Doing ipsec produces a spinlock recursion warning.
This is due to not disabling BH during crypto completion function.

Fixes 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/crypto/amlogic/amlogic-gxl-cipher.c +2 -0
index c6865cbd334b..e79514fce731 100644
@@ -265,7 +265,9 @@ static int meson_handle_cipher_request(struct crypto_engine *engine,
 	struct skcipher_request *breq = container_of(areq, struct skcipher_request, base);
 
 	err = meson_cipher(breq);
+	local_bh_disable();
 	crypto_finalize_skcipher_request(engine, breq, err);
+	local_bh_enable();
 
 	return 0;
 }
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 4/5 crypto: gemini: call finalize with bh disabled

In reply to Corentin Labbe

Doing ipsec produces a spinlock recursion warning.
This is due to not disabling BH during crypto completion function.

Fixes 46c5338db7bd45b2 ("crypto: sl3516 - Add sl3516 crypto engine")
---
 drivers/crypto/gemini/sl3516-ce-cipher.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/crypto/gemini/sl3516-ce-cipher.c +2 -0
index 53e3fefb81de..14d0d83d388d 100644
@@ -264,7 +264,9 @@ static int sl3516_ce_handle_cipher_request(struct crypto_engine *engine, void *a
 	struct skcipher_request *breq = container_of(areq, struct skcipher_request, base);
 
 	err = sl3516_ce_cipher(breq);
+	local_bh_disable();
 	crypto_finalize_skcipher_request(engine, breq, err);
+	local_bh_enable();
 
 	return 0;
 }
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 5/5 crypto: engine: check if BH is disabled during completion

In reply to Corentin Labbe

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

This is due to completion function called with enabled BH.

Add check a to detect this.

Fixes 735d37b5424b ("crypto: engine - Introduce the block request crypto engine framework")
---
 crypto/crypto_engine.c | 1 +
 1 file changed, 1 insertion(+)
crypto/crypto_engine.c +1 -0
index fb07da9920ee..6056a990c9f2 100644
@@ -53,6 +53,7 @@ static void crypto_finalize_request(struct crypto_engine *engine,
 				dev_err(engine->dev, "failed to unprepare request\n");
 		}
 	}
+	lockdep_assert_in_softirq();
 	req->complete(req, err);
 
 	kthread_queue_work(engine->kworker, &engine->pump_requests);
Signature · 1 line
2.34.1
maintainer
#6 lore raw
In reply to Corentin Labbe
Quoted 18 lines · Corentin Labbe

Hello

This is the follow up of https://lore.kernel.org/lkml/Yd1SIHUNdLIvKhzz@Red/
and https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/
This serie fix all drivers which do not call completion with BH disabled
and add the check in crypto/engine asked by Herbert.
I have verified that this check does not generate warnings on all other crypto
hardware I got (omap, ccree, rockchip)

Regards

Corentin Labbe (5):
crypto: sun8i-ss: call finalize with bh disabled
crypto: sun8i-ce: call finalize with bh disabled
crypto: amlogic: call finalize with bh disabled
crypto: gemini: call finalize with bh disabled
crypto: engine: check if BH is disabled during completion

Quoted 8 lines
 crypto/crypto_engine.c                              | 1 +
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c   | 3 +++
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 3 +++
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c   | 3 +++
 drivers/crypto/amlogic/amlogic-gxl-cipher.c         | 2 ++
 drivers/crypto/gemini/sl3516-ce-cipher.c            | 2 ++
 7 files changed, 17 insertions(+)

All applied. Thanks.

Signature · 8 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic