From patchwork Mon May 29 08:22:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 100631 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp230717qge; Mon, 29 May 2017 01:24:21 -0700 (PDT) X-Received: by 10.99.109.199 with SMTP id i190mr17386117pgc.71.1496046261320; Mon, 29 May 2017 01:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496046261; cv=none; d=google.com; s=arc-20160816; b=rf6oojd8ac48FF1TEuGFpDOEJ58d38XmNrdQZJxFmZSKWqpJikPJ4cJLEpbGV91ryf rko7lcypfT4sJrUHAqFjqcCZo3gSmCrrqdwO/+heqaf9PA/S4sJB6c6ICn2Dm1aI1ya4 4ifnwiZuLIn4hoocPKplTpEYJ2ZNam/OZoZ4mULOwp9sHD+Rl7/HtqgU49U3n5lRU/y0 XVmrwgzvRXhYAAAPMmEmQ9egJnEgBkQxR22Pq12TY/Qy0dezZK7jCOb0Ktf2OsKvrGl3 gjCz0PMiTkZu478AENrc0zROuwGHLrOm6sYTaXqdLRPhRtxK0jl5nIOmi3oSi5JScHOk YIaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=RE3gonshiTbibk0m12KDkC4ry/QTdHNs/lXXT4S4EHo=; b=n+9k/kvT4cer9VoNzN7o6YMmXvr5DX/O0JxW0B3F6tmbER3bCC/93+3pqdrEatiopr 3QF63B3om/LtFiA1tdgIi6yjzvhpNlvbOYMAwNvrFxaSQKbx8g/1YMd9lPMHAkiL4KaN bmmgo1RBuOvjbETRkf/vwetoVWfAekvmJNVDNGetRFrqpJtwrXycs4XNehTuxOU/EG+T XC8KlLEm3tcoEfwASOcgOP3u2U2wi8eWwTwEbTaoyNZ6gRvmwaHXr0Xgr1x6jr2vuzdP rS2FE1G9FEM+YAJrIBnoYTPpiyrnpLMxa4CWI01ZA3qjN+lf+iEskXW82Yyea9dAE6/+ WP6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b27si9797556pfh.196.2017.05.29.01.24.21; Mon, 29 May 2017 01:24:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751194AbdE2IYK (ORCPT + 25 others); Mon, 29 May 2017 04:24:10 -0400 Received: from foss.arm.com ([217.140.101.70]:45892 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751037AbdE2IX7 (ORCPT ); Mon, 29 May 2017 04:23:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1D2CE15A1; Mon, 29 May 2017 01:23:54 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56AB53F52A; Mon, 29 May 2017 01:23:47 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Eric Biggers , Ofir Drang , Pavel Shilovsky , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Subject: [PATCH v2 04/11] crypto: move drbg to generic async completion Date: Mon, 29 May 2017 11:22:51 +0300 Message-Id: <1496046180-21962-5-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1496046180-21962-1-git-send-email-gilad@benyossef.com> References: <1496046180-21962-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DRBG is starting an async. crypto op and waiting for it complete. Move it over to generic code doing the same. The code now also passes CRYPTO_TFM_REQ_MAY_SLEEP flag indicating crypto request memory allocation may use GFP_KERNEL which should be perfectly fine as the code is obviously sleeping for the completion of the request any way. Signed-off-by: Gilad Ben-Yossef --- crypto/drbg.c | 34 ++++++++-------------------------- include/crypto/drbg.h | 3 +-- 2 files changed, 9 insertions(+), 28 deletions(-) -- 2.1.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index cdb27ac..101d9f0 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1651,16 +1651,6 @@ static int drbg_fini_sym_kernel(struct drbg_state *drbg) return 0; } -static void drbg_skcipher_cb(struct crypto_async_request *req, int error) -{ - struct drbg_state *drbg = req->data; - - if (error == -EINPROGRESS) - return; - drbg->ctr_async_err = error; - complete(&drbg->ctr_completion); -} - static int drbg_init_sym_kernel(struct drbg_state *drbg) { struct crypto_cipher *tfm; @@ -1699,8 +1689,9 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg) return -ENOMEM; } drbg->ctr_req = req; - skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - drbg_skcipher_cb, drbg); + skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | + CRYPTO_TFM_REQ_MAY_SLEEP, + crypto_req_done, &drbg->ctr_wait); alignmask = crypto_skcipher_alignmask(sk_tfm); drbg->ctr_null_value_buf = kzalloc(DRBG_CTR_NULL_LEN + alignmask, @@ -1761,21 +1752,12 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, /* Output buffer may not be valid for SGL, use scratchpad */ skcipher_request_set_crypt(drbg->ctr_req, &sg_in, &sg_out, cryptlen, drbg->V); - ret = crypto_skcipher_encrypt(drbg->ctr_req); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&drbg->ctr_completion); - if (!drbg->ctr_async_err) { - reinit_completion(&drbg->ctr_completion); - break; - } - default: + ret = crypto_wait_req(crypto_skcipher_encrypt(drbg->ctr_req), + &drbg->ctr_wait); + if (ret) goto out; - } - init_completion(&drbg->ctr_completion); + + crypto_init_wait(&drbg->ctr_wait); memcpy(outbuf, drbg->outscratchpad, cryptlen); diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h index 22f884c..8f94110 100644 --- a/include/crypto/drbg.h +++ b/include/crypto/drbg.h @@ -126,8 +126,7 @@ struct drbg_state { __u8 *ctr_null_value; /* CTR mode aligned zero buf */ __u8 *outscratchpadbuf; /* CTR mode output scratchpad */ __u8 *outscratchpad; /* CTR mode aligned outbuf */ - struct completion ctr_completion; /* CTR mode async handler */ - int ctr_async_err; /* CTR mode async error */ + struct crypto_wait ctr_wait; /* CTR mode async wait obj */ bool seeded; /* DRBG fully seeded? */ bool pr; /* Prediction resistance enabled? */