linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Iuliana Prodan <iuliana.prodan@nxp.com>
To: Corentin Labbe <clabbe.montjoie@gmail.com>,
	"alexandre.torgue@st.com" <alexandre.torgue@st.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"mcoquelin.stm32@gmail.com" <mcoquelin.stm32@gmail.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"wens@csie.org" <wens@csie.org>,
	Horia Geanta <horia.geanta@nxp.com>,
	Aymen Sghaier <aymen.sghaier@nxp.com>
Cc: "linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-stm32@st-md-mailman.stormreply.com" 
	<linux-stm32@st-md-mailman.stormreply.com>,
	"linux-sunxi@googlegroups.com" <linux-sunxi@googlegroups.com>
Subject: Re: [PATCH RFC 05/10] crypto: engine: transform cur_req in an array
Date: Thu, 16 Jan 2020 11:34:09 +0000	[thread overview]
Message-ID: <VI1PR04MB444537D76D295AF3A337039D8C360@VI1PR04MB4445.eurprd04.prod.outlook.com> (raw)
In-Reply-To: 20200114135936.32422-6-clabbe.montjoie@gmail.com

On 1/14/2020 3:59 PM, Corentin Labbe wrote:
> For having the ability of doing a batch of request in one do_one_request(), we
> should be able to store them in an array. (for unpreparing them later).
> This patch converts cur_req in an array of request, but for the moment
> hardcode the maximum to 1.
> 
> Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
> ---
>   crypto/crypto_engine.c  | 32 ++++++++++++++++++--------------
>   include/crypto/engine.h | 19 +++++++++++++++----
>   2 files changed, 33 insertions(+), 18 deletions(-)
> 
> diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
> index eb029ff1e05a..b72873550587 100644
> --- a/crypto/crypto_engine.c
> +++ b/crypto/crypto_engine.c
> @@ -30,26 +30,27 @@ static void crypto_finalize_request(struct crypto_engine *engine,
>   	struct crypto_engine_ctx *enginectx;
>   
>   	spin_lock_irqsave(&engine->queue_lock, flags);
> -	if (engine->cur_req == req)
> +	if (engine->cur_reqs[0].req == req)
>   		finalize_cur_req = true;
>   	spin_unlock_irqrestore(&engine->queue_lock, flags);
>   
>   	if (finalize_cur_req) {
> -		enginectx = crypto_tfm_ctx(req->tfm);
> -		if (engine->cur_req_prepared &&
> +		enginectx = crypto_tfm_ctx(engine->cur_reqs[0].req->tfm);
> +		if (engine->cur_reqs[0].prepared &&
>   		    enginectx->op.unprepare_request) {
> -			ret = enginectx->op.unprepare_request(engine, req);
> +			ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[0].req);
>   			if (ret)
>   				dev_err(engine->dev, "failed to unprepare request\n");
>   		}
> +		engine->cur_reqs[0].req->complete(engine->cur_reqs[0].req, err);
>   		spin_lock_irqsave(&engine->queue_lock, flags);
> -		engine->cur_req = NULL;
> -		engine->cur_req_prepared = false;
> +		engine->cur_reqs[0].prepared = false;
> +		engine->cur_reqs[0].req = NULL;
>   		spin_unlock_irqrestore(&engine->queue_lock, flags);
> +	} else {
> +		req->complete(req, err);
>   	}
>   
> -	req->complete(req, err);
> -
>   	kthread_queue_work(engine->kworker, &engine->pump_requests);
>   }
>   
> @@ -74,7 +75,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,
>   	spin_lock_irqsave(&engine->queue_lock, flags);
>   
>   	/* Make sure we are not already running a request */
> -	if (engine->cur_req)
> +	if (engine->cur_reqs[0].req)
>   		goto out;
>   
>   	/* If another context is idling then defer */
> @@ -114,7 +115,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,
>   	if (!async_req)
>   		goto out;
>   
> -	engine->cur_req = async_req;
> +	engine->cur_reqs[0].req = async_req;
>   	if (backlog)
>   		backlog->complete(backlog, -EINPROGRESS);
>   
> @@ -143,14 +144,14 @@ static void crypto_pump_requests(struct crypto_engine *engine,
>   				ret);
>   			goto req_err;
>   		}
> -		engine->cur_req_prepared = true;
> +		engine->cur_reqs[0].prepared = true;
>   	}
>   	if (!enginectx->op.do_one_request) {
>   		dev_err(engine->dev, "failed to do request\n");
>   		ret = -EINVAL;
>   		goto req_err;
>   	}
> -	ret = enginectx->op.do_one_request(engine, async_req);
> +	ret = enginectx->op.do_one_request(engine, engine->cur_reqs[0].req);
>   	if (ret) {
>   		dev_err(engine->dev, "Failed to do one request from queue: %d\n", ret);
>   		goto req_err;
> @@ -158,7 +159,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,
>   	return;
>   
>   req_err:
> -	crypto_finalize_request(engine, async_req, ret);
> +	crypto_finalize_request(engine, engine->cur_reqs[0].req, ret);
>   	return;
>   
>   out:
> @@ -411,10 +412,13 @@ struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt)
>   	engine->running = false;
>   	engine->busy = false;
>   	engine->idling = false;
> -	engine->cur_req_prepared = false;
>   	engine->priv_data = dev;
>   	snprintf(engine->name, sizeof(engine->name),
>   		 "%s-engine", dev_name(dev));
> +	engine->rmax = 1;
> +	engine->cur_reqs = devm_kzalloc(dev, sizeof(struct cur_req) * engine->rmax, GFP_KERNEL);
> +	if (!engine->cur_reqs)
> +		return NULL;
>   
>   	crypto_init_queue(&engine->queue, CRYPTO_ENGINE_MAX_QLEN);
>   	spin_lock_init(&engine->queue_lock);
> diff --git a/include/crypto/engine.h b/include/crypto/engine.h
> index e29cd67f93c7..362134e226f4 100644
> --- a/include/crypto/engine.h
> +++ b/include/crypto/engine.h
> @@ -18,13 +18,23 @@
>   #include <crypto/skcipher.h>
>   
>   #define ENGINE_NAME_LEN	30
> +
> +/*
> + * struct cur_req - Represent a request to be processed
> + * @prepared:	Does the request was prepared
> + * @req:	The request to be processed
> + */
> +struct cur_req {
> +	bool				prepared;
> +	struct crypto_async_request	*req;
> +};
> +
>   /*
>    * struct crypto_engine - crypto hardware engine
>    * @name: the engine name
>    * @idling: the engine is entering idle state
>    * @busy: request pump is busy
>    * @running: the engine is on working
> - * @cur_req_prepared: current request is prepared
>    * @list: link with the global crypto engine list
>    * @queue_lock: spinlock to syncronise access to request queue
>    * @queue: the crypto queue of the engine
> @@ -38,14 +48,14 @@
>    * @kworker: kthread worker struct for request pump
>    * @pump_requests: work struct for scheduling work to the request pump
>    * @priv_data: the engine private data
> - * @cur_req: the current request which is on processing
> + * @rmax:	The number of request which can be processed in one batch
> + * @cur_reqs: 	A list for requests to be processed
>    */
>   struct crypto_engine {
>   	char			name[ENGINE_NAME_LEN];
>   	bool			idling;
>   	bool			busy;
>   	bool			running;
> -	bool			cur_req_prepared;
>   
>   	struct list_head	list;
>   	spinlock_t		queue_lock;
> @@ -61,7 +71,8 @@ struct crypto_engine {
>   	struct kthread_work             pump_requests;
>   
>   	void				*priv_data;
> -	struct crypto_async_request	*cur_req;
> +	int 				rmax;
> +	struct cur_req 			*cur_reqs;
>   };

To keep requests independent IMO it would be best to have a list of 
requests like: struct requests run_queue, where

struct requests {
	unsigned int max_no_reqs;
	unsigned int current_no_reqs;
	struct cur_req *cur_reqs; //list of the requests
} run_queue;

  reply	other threads:[~2020-01-16 11:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-14 13:59 [PATCH RFC 00/10] crypto: engine: permit to batch requests Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 01/10] crypto: sun8i-ce: move iv data to request context Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 02/10] crypto: sun8i-ce: increase task list size Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 03/10] crypto: sun8i-ce: split into prepare/run/unprepare Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 04/10] crypto: sun8i-ce: introduce the slot number Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 05/10] crypto: engine: transform cur_req in an array Corentin Labbe
2020-01-16 11:34   ` Iuliana Prodan [this message]
2020-01-14 13:59 ` [PATCH RFC 06/10] crypto: engine: introduce ct Corentin Labbe
2020-01-16 11:34   ` Iuliana Prodan
2020-01-16 13:21     ` Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 07/10] crypto: sun8i-ce: handle slot > 0 Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 08/10] crypto: engine: add slot parameter Corentin Labbe
2020-01-14 13:59 ` [PATCH RFC 09/10] crypto: engine: permit to batch requests Corentin Labbe
2020-01-16 11:34   ` Iuliana Prodan
2020-01-17 16:13   ` Iuliana Prodan
2020-01-14 13:59 ` [PATCH RFC 10/10] crypto: sun8i-ce: use the new batch mechanism Corentin Labbe
2020-01-16 11:33 ` [PATCH RFC 00/10] crypto: engine: permit to batch requests Iuliana Prodan
2020-01-16 13:16   ` Corentin Labbe

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=VI1PR04MB444537D76D295AF3A337039D8C360@VI1PR04MB4445.eurprd04.prod.outlook.com \
    --to=iuliana.prodan@nxp.com \
    --cc=alexandre.torgue@st.com \
    --cc=aymen.sghaier@nxp.com \
    --cc=clabbe.montjoie@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-sunxi@googlegroups.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mripard@kernel.org \
    --cc=wens@csie.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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).