Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp502213ybv; Fri, 7 Feb 2020 03:27:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwAS43Qx4+BSCeKlCh0wyzLeIgk6s1reSYsmOqmn0VMpOc1/yCbXkrlaOPqr7Xdcb4k99Q2 X-Received: by 2002:aca:dc45:: with SMTP id t66mr1785045oig.39.1581074830863; Fri, 07 Feb 2020 03:27:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1581074830; cv=pass; d=google.com; s=arc-20160816; b=V544wgW7qyCd+h/6WqqYyQbFHu8aosok5OLioiQeuH/BvvBc3vBfgo7/Jevk5s1ANo zy8cxNN5kvk6BMUjirmNSs2Ida7UoZAKrTZC1gQ1/+1yYn5WJPMltdY9iTWwmEea2cXP 196uxTpRU7kzTi9hBuvftywMJdZK7/dPUnnOl7XbaeL6USi4gT4zzgr8ovLD48bus+Fs 3mMxSry/xzjzlGcSPav7epy4uUtoKQsDT8uRb+Q3TsTV41YMT8hKnGFMTIwee+YatT90 +V/csI0Bfza/tkiqQvAgEZM2mgAfIjF+f+M12zqwFamXnwF+P9FZ3w5IE3fx3syXezYU kuQw== 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=Oh60Z76SN3npqkO38LqYNDbKN8yjHAqbbjyBmnS3mmk=; b=V9lr9XF7z0E2mwgzwADDv8a5FF8q7R9gNRIrxtd5oW9F5gvHJGf4kKgqUYY4EAjjoP H0o/NUyw3h5zhaP88yBU+uNyVbT/rTvhOC97Dn7rjFdk/OTzu096LAvr0WYmk0gLW25A NxLfB9vrfaJSxR4ctXrsBMV49r5uREQRd25dJPB5r4TLbn4zpyGTCEJkST7JJNMfEosO uz2eC3H9yLCM6ZUCzVAUB7ujys+XqZOIfDjcEqunRUJgVZT+3kf5CTyFERCWHyz8dqQ0 8S3R1j+Pr4eRikd8TxtSL9VU24pfksyYu2CSGzyfb32Zuc9sYULUrhyXEtLRcsT2zAxD 9E9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=lygOrMyh; 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 t26si3769336oic.169.2020.02.07.03.26.52; Fri, 07 Feb 2020 03:27:10 -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=lygOrMyh; 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 S1726956AbgBGL0m (ORCPT + 99 others); Fri, 7 Feb 2020 06:26:42 -0500 Received: from mail-eopbgr30042.outbound.protection.outlook.com ([40.107.3.42]:14020 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726798AbgBGL0m (ORCPT ); Fri, 7 Feb 2020 06:26:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JOC+o3PH8/o4Q74/t5/QL+iFfXdLTK70AbI55oBMQ1hNRLFm8wb1bN1+qTd1uWkkDXkvEgN4Aw0dwe23ssRCxp0DEXTTCb32y3IWMJjgxmF1Tkw8L038xdkTAJGMZD6pCJNmluDxm94GUnw0hgdtI125ctK8QxflISyA1EQ/BX+OZy74+ga9epp5jm87eyvmWr9WhIJSkRAJtMdy2uDDmnixUeWcJIYvvBI4B+G/ui0Y3W1Pd1lQASsNN+th0bzHxpHvDMpx9W9kmlyv1UdZhcMxbUikLLzzgYdvb90oZ4zNnGfzr0CfpVvjSljkxIa9WBROi7dLAkTp6KFoTg3J1g== 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=Oh60Z76SN3npqkO38LqYNDbKN8yjHAqbbjyBmnS3mmk=; b=SaN4oljqWp3LCbX4DnnkKfZOuFcghOcGqlKMy0G4uUl/HCyZtRixuS1tXBkhnd6eGuYxqNcdc/pFLbw9DIR+wsL3GF717ArgWURMt8WUp4MtVK830Wh80swdWg2EOz4ixOiKj3Awxiq8RJCH7+G13gRBgd9sbSxnpkinIMdzwNWkgP3hYgB96zyHGkDIGxLyNmR2jyT3iaS9OZu8WGexKHKrrZXLOIqT0oaE9Vq5JcvQD0I84Ut7SVYN/P1LOt5ufJlppXjX55j+hw15cFMmrOvV/tw01GBfR+MFiY6LTyYScPPUDDrvzHnVtcpEdmo1dEBs2Im5aa1aESh3Rz1pWw== 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=Oh60Z76SN3npqkO38LqYNDbKN8yjHAqbbjyBmnS3mmk=; b=lygOrMyhxQa3bXMAAv2WL3X9WzQ4a+N6huxEjS0S/8S8LThiYcT5rFwFuMK81M4VRnpBRim6Mq/Hxu2Tx4cC1KiejwLXM+BphZ/gUIcQoynORI00ZJoG6ZEdl+rbxl7h7xdkKT8t+ccnAxDNIleCDrdiUYMf/Sx4A0t3xBvvH5c= Received: from AM0PR04MB7171.eurprd04.prod.outlook.com (10.186.130.205) by AM0PR04MB4964.eurprd04.prod.outlook.com (20.177.40.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.23; Fri, 7 Feb 2020 11:26:39 +0000 Received: from AM0PR04MB7171.eurprd04.prod.outlook.com ([fe80::b8df:72f3:9624:1256]) by AM0PR04MB7171.eurprd04.prod.outlook.com ([fe80::b8df:72f3:9624:1256%7]) with mapi id 15.20.2707.020; Fri, 7 Feb 2020 11:26:39 +0000 From: Iuliana Prodan To: Corentin Labbe CC: Herbert Xu , Baolin Wang , Ard Biesheuvel , Horia Geanta , Maxime Coquelin , Alexandre Torgue , Maxime Ripard , Aymen Sghaier , "David S. Miller" , Silvano Di Ninno , Franck Lenormand , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH v2 1/2] crypto: engine - support for parallel requests Thread-Topic: [PATCH v2 1/2] crypto: engine - support for parallel requests Thread-Index: AQHV21d9ovH+nULTjUSN5UBY10erRw== Date: Fri, 7 Feb 2020 11:26:38 +0000 Message-ID: References: <1580819660-30211-1-git-send-email-iuliana.prodan@nxp.com> <1580819660-30211-2-git-send-email-iuliana.prodan@nxp.com> <20200205191128.GA32606@Red> 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: fda9f352-b5a6-40be-ef3b-08d7abc09953 x-ms-traffictypediagnostic: AM0PR04MB4964:|AM0PR04MB4964: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 0306EE2ED4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(366004)(376002)(396003)(346002)(136003)(199004)(189003)(4326008)(186003)(6506007)(53546011)(54906003)(26005)(316002)(55016002)(8676002)(81166006)(81156014)(7416002)(5660300002)(8936002)(6916009)(52536014)(9686003)(71200400001)(86362001)(2906002)(66446008)(33656002)(66476007)(66946007)(66556008)(64756008)(76116006)(44832011)(7696005)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4964;H:AM0PR04MB7171.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX: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: NCPVGh+HlATU4jGS2EsfvzJPbiFGtsrX4FLMZor8YEBbkmVW2hRZBwKU3JxA1Vr7kE2G0f3cCedRcVGMJSY6scyJoUN9auVP1ZkRx7E91NxFSvQCW2YJitis5DKRco1vZQ8hPfCkTNOYU/7Sl/hqG0xDNtTsYyovNYTPh+d+DlbgjB24lJMAXXdxazFHsOrczNI8Ht6wKifvz9FlegoUNkgxdzeGV7Q0bjov3qmcHOhLRs006jzxY/OowEL5v2ticS0F1LJEmRcY3yie8J4eZNUqLR2hfGAPIkoyV6vkNPwCL5ljvJh01DWbynISIrlSduBm76TZFXbEckX1SYdXdEs77OJaimHtFVsqO59eOhic/gP/8LbMDGWBGiH0XJkfsmPVsw+E4KKZNRewoOjmHCCa8TwXfiecj1fWQGtqoOCI25KWD5CSAcR76gD9/z3D x-ms-exchange-antispam-messagedata: MDEDPhnVA8plwD+arzy8TrU3O0lfqYRMuPlw2neiGv5XHiKDlEN14SEcIe/w/+g/DaO7A8uExLB2C+ILN2Phhd0O52pMDGWndyb3OLoR4ipuZKVAMTx3KFvxHqUioV3fbAO5lX4RfXaVXEmQfnk7kg== 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: fda9f352-b5a6-40be-ef3b-08d7abc09953 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Feb 2020 11:26:38.9783 (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: RLlB6TidNyd43O+dAL0kgKsUw3kILkoNLegGYoRYH5uR9+X1txZqZg/Pm8i5+lDybNPVfZfo3mE0aGgef0smug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4964 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 2/5/2020 9:11 PM, Corentin Labbe wrote:=0A= > On Tue, Feb 04, 2020 at 02:34:19PM +0200, Iuliana Prodan wrote:=0A= >> Added support for executing multiple requests, in parallel,=0A= >> for crypto engine.=0A= >> A new callback is added, can_enqueue_more, which asks the=0A= >> driver if the hardware has free space, to enqueue a new request.=0A= >> The new crypto_engine_alloc_init_and_set function, initialize=0A= >> crypto-engine, sets the maximum size for crypto-engine software=0A= >> queue (not hardcoded anymore) and the can_enqueue_more callback.=0A= >> On crypto_pump_requests, if can_enqueue_more callback returns true,=0A= >> a new request is send to hardware, until there is no space and the=0A= >> callback returns false.=0A= >>=0A= >> Signed-off-by: Iuliana Prodan =0A= >> ---=0A= >> crypto/crypto_engine.c | 106 ++++++++++++++++++++++++++++++----------= --------=0A= >> include/crypto/engine.h | 10 +++--=0A= >> 2 files changed, 72 insertions(+), 44 deletions(-)=0A= >>=0A= >> diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c=0A= >> index eb029ff..aba934f 100644=0A= >> --- a/crypto/crypto_engine.c=0A= >> +++ b/crypto/crypto_engine.c=0A= >> @@ -22,32 +22,18 @@=0A= >> * @err: error number=0A= >> */=0A= >> static void crypto_finalize_request(struct crypto_engine *engine,=0A= >> - struct crypto_async_request *req, int err)=0A= >> + struct crypto_async_request *req, int err)=0A= >> {=0A= >> - unsigned long flags;=0A= >> - bool finalize_cur_req =3D false;=0A= >> int ret;=0A= >> struct crypto_engine_ctx *enginectx;=0A= >> =0A= >> - spin_lock_irqsave(&engine->queue_lock, flags);=0A= >> - if (engine->cur_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->op.unprepare_request) {=0A= >> - ret =3D enginectx->op.unprepare_request(engine, req);=0A= >> - if (ret)=0A= >> - dev_err(engine->dev, "failed to unprepare request\n");=0A= >> - }=0A= >> - spin_lock_irqsave(&engine->queue_lock, flags);=0A= >> - engine->cur_req =3D NULL;=0A= >> - engine->cur_req_prepared =3D false;=0A= >> - spin_unlock_irqrestore(&engine->queue_lock, flags);=0A= >> + enginectx =3D crypto_tfm_ctx(req->tfm);=0A= >> + if (enginectx->op.prepare_request &&=0A= >> + enginectx->op.unprepare_request) {=0A= >> + ret =3D enginectx->op.unprepare_request(engine, req);=0A= >> + if (ret)=0A= >> + dev_err(engine->dev, "failed to unprepare request\n");=0A= >> }=0A= >> -=0A= >> req->complete(req, err);=0A= >> =0A= >> kthread_queue_work(engine->kworker, &engine->pump_requests);=0A= >> @@ -73,10 +59,6 @@ static void crypto_pump_requests(struct crypto_engine= *engine,=0A= >> =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= >> - goto out;=0A= >> -=0A= > =0A= > Hello=0A= > =0A= > Your patch has the same problem than mine reported by Horia.=0A= > If a queue has more than one request, a first crypto_pump_requests() will= send a request and for drivers which do not block on do_one_request() cryp= to_pump_requests() will end.=0A= > Then another crypto_pump_requests() will fire sending a second request wh= ile the driver does not support that.=0A= =0A= > So we need to replace engine->cur_req by another locking mechanism.=0A= > Perhaps the cleaner is to add a "request count" (increased when do_one_re= quest, decreased in crypto_finalize_request)=0A= > I know that the early version have that and it was removed, but I do not = see any better way.=0A= > =0A= =0A= The "request count" I've change it to can_enqueue_more, so the hw can =0A= "answer" if it can enqueue or not.=0A= =0A= I'll (re)add the cur_req in crypto-engine.=0A= If the new callback, can_enqueue_more, is not implemented the crypto- =0A= engine will work as before - will send requests to hardware, one-by-one, = =0A= on crypto_pump_requests, and complete it, on crypto_finalize_request, =0A= and so on.=0A= =0A= Thanks,=0A= Iulia=0A= =0A=