Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7663829ybl; Thu, 16 Jan 2020 03:34:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyPi9rw112sutmmnmtlDqJ00OLZSwldqv1xuzyeaZMowm50Qo49zyQpfeijqTcevihwy1z/ X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr3722725oij.176.1579174485009; Thu, 16 Jan 2020 03:34:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1579174485; cv=pass; d=google.com; s=arc-20160816; b=F7tiiWYNkJ7r9otpAPXJhjoh3Rq3ua7wgw4QwGq6rBzr4E+8xuS5CKEUKBK/+LA9zS McJ8VH+MVKm9YT+QCkce6tdOJLlrL0fuIyjd9RlgsGOKwvdOiL1OciMrwDZOQ2jX8Mgq o3+fYSnqD5cnM3oqOdoTN7fBbZfsSOnttZP3gxG+gyFu3XiYwRP+30FA01TDhWOVh7as F0d5pO2nm+oJeds9gzJL3kr2FnTI1D02h6F7Snh1FLAnYrLujOIQ6bGHqJ/CMlGZvzt2 zdRBBwkNExmiGznG9AB8a0xFKznnjX95tpxy6lHKFAi4S1MumsBS5HDfs1W7s4VHn+yy b7jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:references:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=1q1/JPqHG2FO/D0IgadxobMkmPtShYsAvrYP2T6FMW4=; b=HsYGCDHkh6owUNHxOLL3nauVPX0DzUG4GIz2Z8sylV/IYA16/rIiWIKea219g97ZjI dTgNT7uX2+y+p/FOLBjGeCuA7dnvFaUHQes4Yv8WZ+otrT6MpRoLSWDJmbcwT74tOxqD IlAN/ifkJ2DRnbPD3h2cXqBLRABbpFI9SfpUHQOef/QkU5JjnFvbkzNPJyOJlKBFwhyp Tlu2E5Obqi2P8aZPx/auzOqBVIhWaamBRSVsrf9yJzUJBQuXR1PZBT1VnqmO6tDB4hGF BN71BYWkjpY7KCvYFgO1e+f29TGtPfDuIL3tRmfzNp3LPNrrRyuNQepNYh/ieZWSwXhY yCfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=rzN5ARw7; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si13242461otp.286.2020.01.16.03.34.26; Thu, 16 Jan 2020 03:34:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=rzN5ARw7; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726084AbgAPLeO (ORCPT + 99 others); Thu, 16 Jan 2020 06:34:14 -0500 Received: from mail-eopbgr40073.outbound.protection.outlook.com ([40.107.4.73]:42626 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725999AbgAPLeO (ORCPT ); Thu, 16 Jan 2020 06:34:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QlWOAa3vpx6i2cUxKuaDf7IY9qsqLiFQJC5Urz3o9yHg40NYt10LbThCpVVhBPfzyjVXKebzPZZkcp8gTGAUkgR/DP54rsCa83hPiq+wubpSGciEZLWSLAau5pp9mw3tDvAGVt64zuc4nUK+5AFkYq8fk/UaHOEHgG5GbTEL/4q/yJHj3SUNFLwR57NK+uMCljlG986vtqLMiqjwiBN8+DYy7O/yATWLFXC+0GZDYm3RFpU0mjWSW/r/e9FUVnbpvPZgRzYlRSL6om2SvZ4SkqmDxVCUr82EeIj3fKl+3vWlKANhYgIOTHgJNFyr7bYcdWmsVO2QBS97ZR3gj0wwDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1q1/JPqHG2FO/D0IgadxobMkmPtShYsAvrYP2T6FMW4=; b=FmqBbogklhPKkxT2bROK/MhJI62mSSzgdrIcCK/LaU+uEfMXhfw0ujgB9EE3Nz/a4zItLzXq1iOKrJ1/KB5xunzQpxRzSQrS+bJwFDbDNFRSrhYDNw3j/4iQJ9b8m6Q6KzdLPTfywATljEHxphoMW4EM9YOgSRgN4KbdOr/dyQsbNXt3RgN3S9OZ3u9iijZBJUL2LTMRuWJcU+tTFBvCKhdGHyKwOtD59+lJPZd4Z99lUuQO6rpUv8Wb5PbBnyuAmbMRSEELzPpes+RuooYcOrSswLzhReSSq+Yu3kmqnBNJ4kgTG5ZY6lZr+DVNNnXGZzQLXsTfpmj5ZNpwcAzssQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1q1/JPqHG2FO/D0IgadxobMkmPtShYsAvrYP2T6FMW4=; b=rzN5ARw7nQgWPKlvVjWDJBucT4fMxhAi5Fk9IzA1uFan7TJeqVEjYl/JP+RbzAM25AtLbrcrCscvawTbiKNpS3MvlWzc+/x6sS0rhFg1MZ+a+UCFbKXZIsBea9rE+9qPD7g7F7hSQdzSFPvzdOD6FNla7jziaZGOrlYLOHCYM38= Received: from VI1PR04MB4445.eurprd04.prod.outlook.com (20.177.55.161) by VI1PR04MB7184.eurprd04.prod.outlook.com (10.186.157.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20; Thu, 16 Jan 2020 11:34:10 +0000 Received: from VI1PR04MB4445.eurprd04.prod.outlook.com ([fe80::304d:b7d8:1233:2ae0]) by VI1PR04MB4445.eurprd04.prod.outlook.com ([fe80::304d:b7d8:1233:2ae0%6]) with mapi id 15.20.2623.018; Thu, 16 Jan 2020 11:34:10 +0000 From: Iuliana Prodan To: Corentin Labbe , "alexandre.torgue@st.com" , "davem@davemloft.net" , "herbert@gondor.apana.org.au" , "mcoquelin.stm32@gmail.com" , "mripard@kernel.org" , "wens@csie.org" , Horia Geanta , Aymen Sghaier CC: "linux-arm-kernel@lists.infradead.org" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-sunxi@googlegroups.com" Subject: Re: [PATCH RFC 05/10] crypto: engine: transform cur_req in an array Thread-Topic: [PATCH RFC 05/10] crypto: engine: transform cur_req in an array Thread-Index: AQHVyuLoLn4V3kbUsEW/6unpDUGQYQ== Date: Thu, 16 Jan 2020 11:34:09 +0000 Message-ID: References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> <20200114135936.32422-6-clabbe.montjoie@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=iuliana.prodan@nxp.com; x-originating-ip: [212.146.100.6] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 03975f72-c4e3-49d8-e225-08d79a780105 x-ms-traffictypediagnostic: VI1PR04MB7184:|VI1PR04MB7184: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 02843AA9E0 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(396003)(376002)(346002)(136003)(39860400002)(189003)(199004)(9686003)(44832011)(8936002)(6636002)(5660300002)(81156014)(81166006)(8676002)(71200400001)(7696005)(4326008)(2906002)(6506007)(316002)(66446008)(66556008)(66476007)(66946007)(64756008)(54906003)(55016002)(110136005)(86362001)(76116006)(478600001)(186003)(53546011)(33656002)(52536014)(26005)(7416002)(91956017);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB7184;H:VI1PR04MB4445.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hrBsgrYduZTlWIChCUXQkrx9vs0LT5UeaO21RvKYd/azLeLmiiHaMr2j9oiXfbhE4tDjRa5UlxDhg7DIoB6Am6QLhSJUq4LyM0YPvM22oSZqSRN/n+DK8Ij17xTl9ps/mFqSpeZCvnvqZaDHHJUzsAiLbFrUb7He9BpA4HNES4KgcEUGm2aemzqgQVB95p8tH3L8jhSLiA/TQiDJ3lDJtsB1bQGGVSEET3nZ9U8vR8j7GN6QOklztRHN9F8jdMtWfk9K193s1X8GOr5mZzNQAsOenS2Iba/cCOtP2U9VCYSLgW7kPHN1Nloav+qPCkA0pnWD18/fcTx+X/V+49LdVH4GJZ8FHUcw0gXYjzrnxGDHNas7mvZMkLel7cVgAqLSLTU3rXJ/5+efW/855hC80Sq6GCqLepr8hlidh0NovhEsFsn7vZOe30cWq+p2WfQT Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03975f72-c4e3-49d8-e225-08d79a780105 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jan 2020 11:34:09.9130 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: y1C+gGUxK5gPeiss0FxOexpPN9tFL4C2x6P/JIw333VVeD7lG736LpKGR+LH6mcd35FzJihwaCRizUL5db9Qcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7184 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 1/14/2020 3:59 PM, Corentin Labbe wrote:=0A= > For having the ability of doing a batch of request in one do_one_request(= ), we=0A= > should be able to store them in an array. (for unpreparing them later).= =0A= > This patch converts cur_req in an array of request, but for the moment=0A= > hardcode the maximum to 1.=0A= > =0A= > Signed-off-by: Corentin Labbe =0A= > ---=0A= > crypto/crypto_engine.c | 32 ++++++++++++++++++--------------=0A= > include/crypto/engine.h | 19 +++++++++++++++----=0A= > 2 files changed, 33 insertions(+), 18 deletions(-)=0A= > =0A= > diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c=0A= > index eb029ff1e05a..b72873550587 100644=0A= > --- a/crypto/crypto_engine.c=0A= > +++ b/crypto/crypto_engine.c=0A= > @@ -30,26 +30,27 @@ static void crypto_finalize_request(struct crypto_eng= ine *engine,=0A= > struct crypto_engine_ctx *enginectx;=0A= > =0A= > spin_lock_irqsave(&engine->queue_lock, flags);=0A= > - if (engine->cur_req =3D=3D req)=0A= > + if (engine->cur_reqs[0].req =3D=3D req)=0A= > finalize_cur_req =3D true;=0A= > spin_unlock_irqrestore(&engine->queue_lock, flags);=0A= > =0A= > if (finalize_cur_req) {=0A= > - enginectx =3D crypto_tfm_ctx(req->tfm);=0A= > - if (engine->cur_req_prepared &&=0A= > + enginectx =3D crypto_tfm_ctx(engine->cur_reqs[0].req->tfm);=0A= > + if (engine->cur_reqs[0].prepared &&=0A= > enginectx->op.unprepare_request) {=0A= > - ret =3D enginectx->op.unprepare_request(engine, req);=0A= > + ret =3D enginectx->op.unprepare_request(engine, engine->cur_reqs[0].r= eq);=0A= > if (ret)=0A= > dev_err(engine->dev, "failed to unprepare request\n");=0A= > }=0A= > + engine->cur_reqs[0].req->complete(engine->cur_reqs[0].req, err);=0A= > spin_lock_irqsave(&engine->queue_lock, flags);=0A= > - engine->cur_req =3D NULL;=0A= > - engine->cur_req_prepared =3D false;=0A= > + engine->cur_reqs[0].prepared =3D false;=0A= > + engine->cur_reqs[0].req =3D NULL;=0A= > spin_unlock_irqrestore(&engine->queue_lock, flags);=0A= > + } else {=0A= > + req->complete(req, err);=0A= > }=0A= > =0A= > - req->complete(req, err);=0A= > -=0A= > kthread_queue_work(engine->kworker, &engine->pump_requests);=0A= > }=0A= > =0A= > @@ -74,7 +75,7 @@ static void crypto_pump_requests(struct crypto_engine *= engine,=0A= > spin_lock_irqsave(&engine->queue_lock, flags);=0A= > =0A= > /* Make sure we are not already running a request */=0A= > - if (engine->cur_req)=0A= > + if (engine->cur_reqs[0].req)=0A= > goto out;=0A= > =0A= > /* If another context is idling then defer */=0A= > @@ -114,7 +115,7 @@ static void crypto_pump_requests(struct crypto_engine= *engine,=0A= > if (!async_req)=0A= > goto out;=0A= > =0A= > - engine->cur_req =3D async_req;=0A= > + engine->cur_reqs[0].req =3D async_req;=0A= > if (backlog)=0A= > backlog->complete(backlog, -EINPROGRESS);=0A= > =0A= > @@ -143,14 +144,14 @@ static void crypto_pump_requests(struct crypto_engi= ne *engine,=0A= > ret);=0A= > goto req_err;=0A= > }=0A= > - engine->cur_req_prepared =3D true;=0A= > + engine->cur_reqs[0].prepared =3D true;=0A= > }=0A= > if (!enginectx->op.do_one_request) {=0A= > dev_err(engine->dev, "failed to do request\n");=0A= > ret =3D -EINVAL;=0A= > goto req_err;=0A= > }=0A= > - ret =3D enginectx->op.do_one_request(engine, async_req);=0A= > + ret =3D enginectx->op.do_one_request(engine, engine->cur_reqs[0].req);= =0A= > if (ret) {=0A= > dev_err(engine->dev, "Failed to do one request from queue: %d\n", ret= );=0A= > goto req_err;=0A= > @@ -158,7 +159,7 @@ static void crypto_pump_requests(struct crypto_engine= *engine,=0A= > return;=0A= > =0A= > req_err:=0A= > - crypto_finalize_request(engine, async_req, ret);=0A= > + crypto_finalize_request(engine, engine->cur_reqs[0].req, ret);=0A= > return;=0A= > =0A= > out:=0A= > @@ -411,10 +412,13 @@ struct crypto_engine *crypto_engine_alloc_init(stru= ct device *dev, bool rt)=0A= > engine->running =3D false;=0A= > engine->busy =3D false;=0A= > engine->idling =3D false;=0A= > - engine->cur_req_prepared =3D false;=0A= > engine->priv_data =3D dev;=0A= > snprintf(engine->name, sizeof(engine->name),=0A= > "%s-engine", dev_name(dev));=0A= > + engine->rmax =3D 1;=0A= > + engine->cur_reqs =3D devm_kzalloc(dev, sizeof(struct cur_req) * engine-= >rmax, GFP_KERNEL);=0A= > + if (!engine->cur_reqs)=0A= > + return NULL;=0A= > =0A= > crypto_init_queue(&engine->queue, CRYPTO_ENGINE_MAX_QLEN);=0A= > spin_lock_init(&engine->queue_lock);=0A= > diff --git a/include/crypto/engine.h b/include/crypto/engine.h=0A= > index e29cd67f93c7..362134e226f4 100644=0A= > --- a/include/crypto/engine.h=0A= > +++ b/include/crypto/engine.h=0A= > @@ -18,13 +18,23 @@=0A= > #include =0A= > =0A= > #define ENGINE_NAME_LEN 30=0A= > +=0A= > +/*=0A= > + * struct cur_req - Represent a request to be processed=0A= > + * @prepared: Does the request was prepared=0A= > + * @req: The request to be processed=0A= > + */=0A= > +struct cur_req {=0A= > + bool prepared;=0A= > + struct crypto_async_request *req;=0A= > +};=0A= > +=0A= > /*=0A= > * struct crypto_engine - crypto hardware engine=0A= > * @name: the engine name=0A= > * @idling: the engine is entering idle state=0A= > * @busy: request pump is busy=0A= > * @running: the engine is on working=0A= > - * @cur_req_prepared: current request is prepared=0A= > * @list: link with the global crypto engine list=0A= > * @queue_lock: spinlock to syncronise access to request queue=0A= > * @queue: the crypto queue of the engine=0A= > @@ -38,14 +48,14 @@=0A= > * @kworker: kthread worker struct for request pump=0A= > * @pump_requests: work struct for scheduling work to the request pump= =0A= > * @priv_data: the engine private data=0A= > - * @cur_req: the current request which is on processing=0A= > + * @rmax: The number of request which can be processed in one batch=0A= > + * @cur_reqs: A list for requests to be processed=0A= > */=0A= > struct crypto_engine {=0A= > char name[ENGINE_NAME_LEN];=0A= > bool idling;=0A= > bool busy;=0A= > bool running;=0A= > - bool cur_req_prepared;=0A= > =0A= > struct list_head list;=0A= > spinlock_t queue_lock;=0A= > @@ -61,7 +71,8 @@ struct crypto_engine {=0A= > struct kthread_work pump_requests;=0A= > =0A= > void *priv_data;=0A= > - struct crypto_async_request *cur_req;=0A= > + int rmax;=0A= > + struct cur_req *cur_reqs;=0A= > };=0A= =0A= To keep requests independent IMO it would be best to have a list of =0A= requests like: struct requests run_queue, where=0A= =0A= struct requests {=0A= unsigned int max_no_reqs;=0A= unsigned int current_no_reqs;=0A= struct cur_req *cur_reqs; //list of the requests=0A= } run_queue;=0A=