Skip to contentSkip to conversation

crypto: virtio-crypto: Handle dataq logic with tasklet

PATCH In review Gonglei (Arei) 2 participants 3 messages Dec 6, 2023 – Dec 8, 2023

Subsystems (3)
lore
Share & tools
lore

Gonglei (Arei)

author maintainer
#0 lore raw

PATCH v2 1/1 crypto: virtio-crypto: Handle dataq logic with tasklet

Doing ipsec produces a spinlock recursion warning.
This is due to crypto_finalize_request() being called in the upper half. Move virtual data queue processing of virtio-crypto driver to tasklet.

Fixes dbaf0624ffa5 ("crypto: add virtio-crypto driver")

---
v2: calling tasklet_kill() in virtcrypto_remove(), thanks for MST.

 drivers/crypto/virtio/virtio_crypto_common.h |  2 ++
 drivers/crypto/virtio/virtio_crypto_core.c   | 26 ++++++++++++++++----------
 2 files changed, 18 insertions(+), 10 deletions(-)
drivers/crypto/virtio/virtio_crypto_common.h +2 -0
index 154590e..7059bbe 100644
@@ -10,6 +10,7 @@
 #include <linux/virtio.h>
 #include <linux/crypto.h>
 #include <linux/spinlock.h>
+#include <linux/interrupt.h>
 #include <crypto/aead.h>
 #include <crypto/aes.h>
 #include <crypto/engine.h>
@@ -28,6 +29,7 @@ struct data_queue {
 	char name[32];
 
 	struct crypto_engine *engine;
+	struct tasklet_struct done_task;
 };
 
 struct virtio_crypto {
drivers/crypto/virtio/virtio_crypto_core.c +16 -10
index 43a0838..b909c6a 100644
@@ -72,27 +72,28 @@ int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct scatterl
 	return 0;
 }
 
-static void virtcrypto_dataq_callback(struct virtqueue *vq)
+static void virtcrypto_done_task(unsigned long data)
 {
-	struct virtio_crypto *vcrypto = vq->vdev->priv;
+	struct data_queue *data_vq = (struct data_queue *)data;
+	struct virtqueue *vq = data_vq->vq;
 	struct virtio_crypto_request *vc_req;
-	unsigned long flags;
 	unsigned int len;
-	unsigned int qid = vq->index;
 
-	spin_lock_irqsave(&vcrypto->data_vq[qid].lock, flags);
 	do {
 		virtqueue_disable_cb(vq);
 		while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) {
-			spin_unlock_irqrestore(
-				&vcrypto->data_vq[qid].lock, flags);
 			if (vc_req->alg_cb)
 				vc_req->alg_cb(vc_req, len);
-			spin_lock_irqsave(
-				&vcrypto->data_vq[qid].lock, flags);
 		}
 	} while (!virtqueue_enable_cb(vq));
-	spin_unlock_irqrestore(&vcrypto->data_vq[qid].lock, flags);
+}
+
+static void virtcrypto_dataq_callback(struct virtqueue *vq)
+{
+	struct virtio_crypto *vcrypto = vq->vdev->priv;
+	struct data_queue *dq = &vcrypto->data_vq[vq->index];
+
+	tasklet_schedule(&dq->done_task);
 }
 
 static int virtcrypto_find_vqs(struct virtio_crypto *vi)
@@ -150,6 +151,8 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
 			ret = -ENOMEM;
 			goto err_engine;
 		}
+		tasklet_init(&vi->data_vq[i].done_task, virtcrypto_done_task,
+				(unsigned long)&vi->data_vq[i]);
 	}
 
 	kfree(names);
@@ -497,12 +500,15 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
 static void virtcrypto_remove(struct virtio_device *vdev)
 {
 	struct virtio_crypto *vcrypto = vdev->priv;
+	int i;
 
 	dev_info(&vdev->dev, "Start virtcrypto_remove.\n");
 
 	flush_work(&vcrypto->config_work);
 	if (virtcrypto_dev_started(vcrypto))
 		virtcrypto_dev_stop(vcrypto);
+	for (i = 0; i < vcrypto->max_data_queues; i++)
+		tasklet_kill(&vcrypto->data_vq[i].done_task);
 	virtio_reset_device(vdev);
 	virtcrypto_free_unused_reqs(vcrypto);
 	virtcrypto_clear_crypto_engines(vcrypto);
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 8 lines · Gonglei (Arei)

Doing ipsec produces a spinlock recursion warning.
This is due to crypto_finalize_request() being called in the upper half. Move virtual data queue processing of virtio-crypto driver to tasklet.

Fixes dbaf0624ffa5 ("crypto: add virtio-crypto driver")
Quoted 6 lines

---
v2: calling tasklet_kill() in virtcrypto_remove(), thanks for MST.

 drivers/crypto/virtio/virtio_crypto_common.h |  2 ++
 drivers/crypto/virtio/virtio_crypto_core.c   | 26 ++++++++++++++++----------
 2 files changed, 18 insertions(+), 10 deletions(-)

Your patch has already been merged. So please send this as an incremental patch.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author maintainer
#2 lore raw
Quoted 24 lines

-----Original Message-----
From: Herbert Xu [mailto:[email protected]]
Sent: Friday, December 8, 2023 11:28 AM
To: Gonglei (Arei) <[email protected]>
Cc: [email protected]; Michael S. Tsirkin <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; wangyangxin <[email protected]>; Halil Pasic <[email protected]>
Subject: Re: [PATCH v2] crypto: virtio-crypto: Handle dataq logic with tasklet

Quoted 11 lines · Gonglei (Arei)

Doing ipsec produces a spinlock recursion warning.
This is due to crypto_finalize_request() being called in the upper half. Move virtual data queue processing of virtio-crypto driver to tasklet.

Fixes dbaf0624ffa5 ("crypto: add virtio-crypto driver")

---
v2: calling tasklet_kill() in virtcrypto_remove(), thanks for MST.

Quoted 8 lines
Quoted 2 lines
 drivers/crypto/virtio/virtio_crypto_common.h |  2 ++
 drivers/crypto/virtio/virtio_crypto_core.c   | 26

++++++++++++++++----------

Quoted 1 line
 2 files changed, 18 insertions(+), 10 deletions(-)

Your patch has already been merged. So please send this as an incremental patch.

OK. No problem.

Regards,
-Gonglei

Quoted 5 lines

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