lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200122104528.30084-6-clabbe.montjoie@gmail.com>
Date:   Wed, 22 Jan 2020 11:45:24 +0100
From:   Corentin Labbe <clabbe.montjoie@...il.com>
To:     davem@...emloft.net, herbert@...dor.apana.org.au,
        mripard@...nel.org, wens@...e.org, iuliana.prodan@....com
Cc:     linux-arm-kernel@...ts.infradead.org, linux-crypto@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-sunxi@...glegroups.com,
        Corentin Labbe <clabbe.montjoie@...il.com>
Subject: [PATCH 5/9] crypto: engine: add enqueue_request/can_do_more

This patchs adds two new function wrapper in crypto_engine.
- enqueue_request() for drivers enqueuing request to hardware.
- can_queue_more() for letting drivers to tell if they can
enqueue/prepare more.

Since some drivers (like caam) only enqueue request without "doing"
them, do_one_request() is now optional.

Signed-off-by: Corentin Labbe <clabbe.montjoie@...il.com>
---
 crypto/crypto_engine.c  | 25 ++++++++++++++++++++++---
 include/crypto/engine.h | 14 ++++++++------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
index 5bcb1e740fd9..4a28548c49aa 100644
--- a/crypto/crypto_engine.c
+++ b/crypto/crypto_engine.c
@@ -83,6 +83,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,
 		goto out;
 	}
 
+retry:
 	/* Get the fist request from the engine queue to handle */
 	backlog = crypto_get_backlog(&engine->queue);
 	async_req = crypto_dequeue_request(&engine->queue);
@@ -118,10 +119,28 @@ static void crypto_pump_requests(struct crypto_engine *engine,
 			goto req_err2;
 		}
 	}
+
+	if (enginectx->op.enqueue_request) {
+		ret = enginectx->op.enqueue_request(engine, async_req);
+		if (ret) {
+			dev_err(engine->dev, "failed to enqueue request: %d\n",
+				ret);
+			goto req_err;
+		}
+	}
+	if (enginectx->op.can_queue_more && engine->queue.qlen > 0) {
+		ret = enginectx->op.can_queue_more(engine, async_req);
+		if (ret > 0) {
+			spin_lock_irqsave(&engine->queue_lock, flags);
+			goto retry;
+		}
+		if (ret < 0) {
+			dev_err(engine->dev, "failed to call can_queue_more\n");
+			/* TODO */
+		}
+	}
 	if (!enginectx->op.do_one_request) {
-		dev_err(engine->dev, "failed to do request\n");
-		ret = -EINVAL;
-		goto req_err;
+		return;
 	}
 	ret = enginectx->op.do_one_request(engine, async_req);
 	if (ret) {
diff --git a/include/crypto/engine.h b/include/crypto/engine.h
index 03d9f9ec1cea..8ab9d26e30fe 100644
--- a/include/crypto/engine.h
+++ b/include/crypto/engine.h
@@ -63,14 +63,16 @@ struct crypto_engine {
  * @prepare__request: do some prepare if need before handle the current request
  * @unprepare_request: undo any work done by prepare_request()
  * @do_one_request: do encryption for current request
+ * @enqueue_request:	Enqueue the request in the hardware
+ * @can_queue_more:	if this function return > 0, it will tell the crypto
+ * 	engine that more space are availlable for prepare/enqueue request
  */
 struct crypto_engine_op {
-	int (*prepare_request)(struct crypto_engine *engine,
-			       void *areq);
-	int (*unprepare_request)(struct crypto_engine *engine,
-				 void *areq);
-	int (*do_one_request)(struct crypto_engine *engine,
-			      void *areq);
+	int (*prepare_request)(struct crypto_engine *engine, void *areq);
+	int (*unprepare_request)(struct crypto_engine *engine, void *areq);
+	int (*do_one_request)(struct crypto_engine *engine, void *areq);
+	int (*enqueue_request)(struct crypto_engine *engine, void *areq);
+	int (*can_queue_more)(struct crypto_engine *engine, void *areq);
 };
 
 struct crypto_engine_ctx {
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ