Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133AbdFPVBv (ORCPT ); Fri, 16 Jun 2017 17:01:51 -0400 Received: from mail-ve1eur01on0088.outbound.protection.outlook.com ([104.47.1.88]:54448 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750792AbdFPVBt (ORCPT ); Fri, 16 Jun 2017 17:01:49 -0400 From: =?iso-8859-2?Q?Horia_Geant=E3?= To: Herbert Xu CC: David Gstir , Dan Douglass , "davem@davemloft.net" , Radu Solea , "richard@sigma-star.at" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [RFC PATCH 0/2] crypto: caam - fix cts(cbc(aes)) with CAAM driver Thread-Topic: [RFC PATCH 0/2] crypto: caam - fix cts(cbc(aes)) with CAAM driver Thread-Index: AQHS25tCyorrZx6/xka98MRBFLZ7gw== Date: Fri, 16 Jun 2017 21:01:45 +0000 Message-ID: References: <20170602122446.2427-1-david@sigma-star.at> <20170616075941.GA5346@gondor.apana.org.au> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: gondor.apana.org.au; dkim=none (message not signed) header.d=none;gondor.apana.org.au; dmarc=none action=none header.from=nxp.com; x-originating-ip: [192.88.146.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0401MB2624;7:jx0BAE9q7foqJ3sWixFiJrvzFT16D8w2WFsm0rtPFo5gIPNM2IS7yPMuCN/D70/t8KBsIanlQjvZPqJsM9rRNHS/k+L6KUbiSLsJ3QXgld+Ca5OargvVK42leaTEEuHDcT7Ney3lSCoYnb/i6Wk2snQXpzNpntMKQ7vse+yWs2omUKhZv/OE0dgWFtHErLYoeUNBHv0cAUAw6+2/nPct9rU2dzQW/WX78z3HA58KNl53Mu/yaetInyTl0ATeJ0Qhg7ovAqgtoTz6KAh7Y5epeGuuL3OYbpZMMGee7ZuvWk+gBjBYTzTfjlFXCUQX0E5ZE2+tTJkZa5spwAZyHnkAWdIXlshrte8M/86urDmYV7gelwQcJeAGRRwHT/DGgcPi2X8gcejd03694SgSYu2K7PVLjdiIOROWPmQatpVXN+PTcJv6Bo684GR3DNq0amwA6vGcMoWTxGJgKtINC+FAInb86kb6AVXe0XacKJpIbvWGrV19+AAr0gCtZK0yPoVPeEZohGOvTYtTnCQVzTYLVvAT+KTs5xmmfjsSLbPYtDSCvP6xoBgRMfg4cAkQGdP1tOUI60OSzVsT2I8Ger7NYhW8aXzziYqY+EuXGqfAz0yX4exvf4trI6Br85hduZU9XXfhSMmLmUIj8qSBwsKDa+gxNMObCz84Pu7jSUG5myJG2Q0MIP0f4k/SwhYAFuypMZQY+sWp/yL/tlqAAIjf8gj9RIMkTYv21uHiHRvttjjqSds2DS4EgRhgH1Z4j5SbWOF2h8MJ6X3EZh6/pGFJ1HLYJlsi17QF82H6ORq7yv8= x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39410400002)(39400400002)(39850400002)(39860400002)(39840400002)(39450400003)(24454002)(377454003)(76176999)(50986999)(3846002)(8936002)(74316002)(478600001)(8676002)(53546009)(81166006)(5660300001)(102836003)(93886004)(25786009)(86362001)(6116002)(5250100002)(3660700001)(2900100001)(66066001)(4326008)(33656002)(3280700002)(6436002)(189998001)(99286003)(55016002)(54906002)(53936002)(7696004)(14454004)(6916009)(2906002)(7736002)(54356999)(110136004)(6246003)(305945005)(9686003)(6506006)(38730400002)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2624;H:VI1PR0401MB2591.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; x-ms-traffictypediagnostic: VI1PR0401MB2624: x-ms-office365-filtering-correlation-id: 2c86038b-aaca-4c97-3070-08d4b4fae59f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081);SRVR:VI1PR0401MB2624; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0401MB2624;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0401MB2624; x-forefront-prvs: 0340850FCD spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jun 2017 21:01:45.2540 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2624 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v5GL22Ru015158 Content-Length: 1380 Lines: 32 On 6/16/2017 11:00 AM, Herbert Xu wrote: > On Fri, Jun 16, 2017 at 07:57:00AM +0000, Horia Geant? wrote: >> >> Commit 0605c41cc53ca ("crypto: cts - Convert to skcipher") appends >> CRYPTO_TFM_REQ_MAY_BACKLOG to the original crypto request flags for the >> last block - when calling cts_cbc_encrypt(). >> Is it really needed? > > Yes, because at this point we cannot tell the sender to back off. > >> For cts(cbc(aes)) with cbc(aes) offloaded in HW, i.e. running in async >> mode, we get the below stack for CAAM driver. >> Driver is told that it can sleep (CRYPTO_TFM_REQ_MAY_BACKLOG flag), so >> it uses GFP_KERNEL to allocate memory. However, this is incorrect, since >> driver runs in atomic context (softirq). > > This is wrong. Whether you can sleep or not is determined by > MAY_SLEEP, not MAY_BACKLOG. MAY_BACKLOG only indicates that this > request must be queued, even if the queue is full. > Indeed, CAAM driver incorrectly decides to use GFP_KERNEL for allocation when MAY_BACKLOG flag is set. This seems to be a long-standing issue, I will send a fix (separately). Still I think we have a problem. David reported that the user is fscrypt. Looking into fscrypt code, I see that besides MAY_BACKLOG, MAY_SLEEP flag is also set. So we end up in the situation I described earlier: the last block is encrypted in atomic context and with MAY_SLEEP set. Thanks, Horia