From patchwork Tue Sep 5 12:38:40 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: 111668 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2782035qge; Tue, 5 Sep 2017 05:39:43 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5C+w+l+yxq0ollpznfgNn+zicHxenmo7qg011v+aky3BUjrrrLfSwq44qE0ZRwPtqjOckJ X-Received: by 10.84.133.37 with SMTP id 34mr4389983plf.362.1504615183647; Tue, 05 Sep 2017 05:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615183; cv=none; d=google.com; s=arc-20160816; b=1Ay0wimUfUY4tj85SDeYwcCx8ttvM3XznwUc+SWdNdp5sMKaEpkg9d0kiiqw9giiAH 2NBkC19Xip6aoUDlVfB1ZcCld+Z2L3YSGQiEZkqAfZ4BrQrC47TY59NuvOQu65JMDrly wre05r7mfXa45p1IDr7iTnqy+feaPL/ZKgcMdjoAJyzJrBNqznV5CgnIN7W3BUKuAsgb JpMgy0fn73cOyfH1a8bZhkkNYA3E95EIUEXxUd+Cei5K4aIeYcsUKE/fkRyoxcMQeFTm Q08geS7e+fD2gxSVpdG+GcQWQXGEp411rWS+lNqYPDzA3k3k2fgQCM8SaZj/kPNtaf48 ql5A== 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=fBiGc8d4zT4pq20ENWC2+37g6ckLifpy2oId3WtUBSs=; b=qKhY37VVHBAMC1CFwAtg5hr7Fc+v5UHEF6T1UfaOA0Yc7IP0/xsGCPO260TP9S4YTB PVKpTi1MSIcUBN+EAF9OhBcuIjDHG0TVqrFTqvLJYMNHxvLuMa0B577Yqxr3mubbHuyG uc7Asw1uNtObjQhlu8Yf8hR1wdPr8Pawz4uI8/XT4aEeqJHeG8c/lMdWQbrMwGiLSo5g wl+ZztVwefroIU1cXsrdBbccaCfj6IKeX0FWZxKhsXav5eh2Zcl4edprCDP9KUke2SPK fkRh0/RBlPNtQv+GOypRExZZp9v8TafICuGa5vfQHOy4WYpgmzdgU9HD2sNixtvu9g7U U+WA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si310136plb.197.2017.09.05.05.39.43; Tue, 05 Sep 2017 05:39:43 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751420AbdIEMjk (ORCPT + 1 other); Tue, 5 Sep 2017 08:39:40 -0400 Received: from foss.arm.com ([217.140.101.70]:38928 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750891AbdIEMjf (ORCPT ); Tue, 5 Sep 2017 08:39:35 -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 880DD15BF; Tue, 5 Sep 2017 05:39:34 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8809E3F3E1; Tue, 5 Sep 2017 05:39:25 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 01/20] crypto: change transient busy return code to -EAGAIN Date: Tue, 5 Sep 2017 15:38:40 +0300 Message-Id: <1504615144-29770-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The crypto API was using the -EBUSY return value to indicate both a hard failure to submit a crypto operation into a transformation provider when the latter was busy and the backlog mechanism was not enabled as well as a notification that the operation was queued into the backlog when the backlog mechanism was enabled. Having the same return code indicate two very different conditions depending on a flag is both error prone and requires extra runtime check like the following to discern between the cases: if (err == -EINPROGRESS || (err == -EBUSY && (ahash_request_flags(req) & CRYPTO_TFM_REQ_MAY_BACKLOG))) This patch changes the return code used to indicate a crypto op failed due to the transformation provider being transiently busy to -EAGAIN. Signed-off-by: Gilad Ben-Yossef --- crypto/algapi.c | 6 ++++-- crypto/algif_hash.c | 20 +++++++++++++++++--- crypto/cryptd.c | 4 +--- 3 files changed, 22 insertions(+), 8 deletions(-) -- 2.1.4 diff --git a/crypto/algapi.c b/crypto/algapi.c index aa699ff..916bee3 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -897,9 +897,11 @@ int crypto_enqueue_request(struct crypto_queue *queue, int err = -EINPROGRESS; if (unlikely(queue->qlen >= queue->max_qlen)) { - err = -EBUSY; - if (!(request->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (!(request->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) { + err = -EAGAIN; goto out; + } + err = -EBUSY; if (queue->backlog == &queue->list) queue->backlog = &request->list; } diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 5e92bd2..3b3c154 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -39,6 +39,20 @@ struct algif_hash_tfm { bool has_key; }; +/* Previous versions of crypto_* ops used to return -EBUSY + * rather than -EAGAIN to indicate being tied up. The in + * kernel API changed but we don't want to break the user + * space API. As only the hash user interface exposed this + * error ever to the user, do the translation here. + */ +static inline int crypto_user_err(int err) +{ + if (err == -EAGAIN) + return -EBUSY; + + return err; +} + static int hash_alloc_result(struct sock *sk, struct hash_ctx *ctx) { unsigned ds; @@ -136,7 +150,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, unlock: release_sock(sk); - return err ?: copied; + return err ? crypto_user_err(err) : copied; } static ssize_t hash_sendpage(struct socket *sock, struct page *page, @@ -188,7 +202,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, unlock: release_sock(sk); - return err ?: size; + return err ? crypto_user_err(err) : size; } static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, @@ -236,7 +250,7 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, hash_free_result(sk, ctx); release_sock(sk); - return err ?: len; + return err ? crypto_user_err(err) : len; } static int hash_accept(struct socket *sock, struct socket *newsock, int flags, diff --git a/crypto/cryptd.c b/crypto/cryptd.c index 0508c48..d1dbdce 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c @@ -137,16 +137,14 @@ static int cryptd_enqueue_request(struct cryptd_queue *queue, int cpu, err; struct cryptd_cpu_queue *cpu_queue; atomic_t *refcnt; - bool may_backlog; cpu = get_cpu(); cpu_queue = this_cpu_ptr(queue->cpu_queue); err = crypto_enqueue_request(&cpu_queue->queue, request); refcnt = crypto_tfm_ctx(request->tfm); - may_backlog = request->flags & CRYPTO_TFM_REQ_MAY_BACKLOG; - if (err == -EBUSY && !may_backlog) + if (err == -EAGAIN) goto out_put_cpu; queue_work_on(cpu, kcrypto_wq, &cpu_queue->work); From patchwork Tue Sep 5 12:38:41 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: 111669 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2782327qge; Tue, 5 Sep 2017 05:39:57 -0700 (PDT) X-Google-Smtp-Source: ADKCNb6OmnXyZm9Vld0zFOCko+E1G0VNMZdVQUtIRuvu+q9xQm27GMe66J0We/AI0YDZL3gtreFU X-Received: by 10.101.81.195 with SMTP id i3mr4028729pgq.246.1504615197825; Tue, 05 Sep 2017 05:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615197; cv=none; d=google.com; s=arc-20160816; b=KHhQpKwaJ0viLIuS6e0Vl7Dcg2gvDbnvRqTK3Rgof22YxA8DdFlm3GzJQVW32rQvsV FVq1Ez8OCyn8+UuDbU0sxiveTnJq5CDg83zzp9Jkz7RuQiojSmt96TVC+5iTaagBgCe9 85A87EBBxJGIBsqZxyJ2Uq6DRngc4FeifxRutpG0bxoQcaeIb6gj4q16T7D7EBNaccCj Pcz5bG9DYKkMpbROnp/CX3kpo6kOjhOh/QBl7AilgGL3qY+k0nI/b+5kTPx2cPD/JEaf pR71Q7ClMqEaa8CY+nuBz0xUpTZrtv1rBgzeIEhbb0FufdDsNyQ5K6XY2o3J9uzNuE4/ yK6A== 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=DKt0fGd3ED+OQtQ7v54132dGwRcA27EW1LVW4ooRB3I=; b=OyWziH0LdB2RHGH9azDVKq8u9s94htsd3tF8h2PmKIhJ8icGNOKiVEcQIQGKySYd45 /9wnyO1h7HJqBRi0n6R+1zXH7PlZCngl53VD2TgvNnb4THpNLEX/WijhvIL8cGD3N0hF Dj2hRoFPLxUTyd31VWFwWenFrdz5BzInElQpw1rbym8RJBvnBqHWLgzDZt4/Z2rleWTb aHE6bJVWucN6X05qd6EFxo3/m4thXZaQLrVnUPD0V6hrrCpDmOwAt8NcAnqaedqSreNQ dcZd5hNOKA3OUw5Vm9nvWKa7vDB1/Nv3b5HyX5Rus9E31iT7IDN0zfkA8zQ9Znv3jknt ZmWw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si196243pge.629.2017.09.05.05.39.57; Tue, 05 Sep 2017 05:39:57 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751564AbdIEMjz (ORCPT + 1 other); Tue, 5 Sep 2017 08:39:55 -0400 Received: from foss.arm.com ([217.140.101.70]:38974 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538AbdIEMju (ORCPT ); Tue, 5 Sep 2017 08:39:50 -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 910141650; Tue, 5 Sep 2017 05:39:49 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1853D3F3E1; Tue, 5 Sep 2017 05:39:39 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 02/20] crypto: ccp: use -EAGAIN for transient busy indication Date: Tue, 5 Sep 2017 15:38:41 +0300 Message-Id: <1504615144-29770-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Replace -EBUSY with -EAGAIN when reporting transient busy indication in the absence of backlog. Signed-off-by: Gilad Ben-Yossef Reviewed-by: Gary R Hook --- Please squash this patch with the previous one when merging upstream. --- drivers/crypto/ccp/ccp-crypto-main.c | 8 +++----- drivers/crypto/ccp/ccp-dev.c | 7 +++++-- 2 files changed, 8 insertions(+), 7 deletions(-) -- 2.1.4 diff --git a/drivers/crypto/ccp/ccp-crypto-main.c b/drivers/crypto/ccp/ccp-crypto-main.c index 35a9de7..403ff0a 100644 --- a/drivers/crypto/ccp/ccp-crypto-main.c +++ b/drivers/crypto/ccp/ccp-crypto-main.c @@ -222,9 +222,10 @@ static int ccp_crypto_enqueue_cmd(struct ccp_crypto_cmd *crypto_cmd) /* Check if the cmd can/should be queued */ if (req_queue.cmd_count >= CCP_CRYPTO_MAX_QLEN) { - ret = -EBUSY; - if (!(crypto_cmd->cmd->flags & CCP_CMD_MAY_BACKLOG)) + if (!(crypto_cmd->cmd->flags & CCP_CMD_MAY_BACKLOG)) { + ret = -EAGAIN; goto e_lock; + } } /* Look for an entry with the same tfm. If there is a cmd @@ -243,9 +244,6 @@ static int ccp_crypto_enqueue_cmd(struct ccp_crypto_cmd *crypto_cmd) ret = ccp_enqueue_cmd(crypto_cmd->cmd); if (!ccp_crypto_success(ret)) goto e_lock; /* Error, don't queue it */ - if ((ret == -EBUSY) && - !(crypto_cmd->cmd->flags & CCP_CMD_MAY_BACKLOG)) - goto e_lock; /* Not backlogging, don't queue it */ } if (req_queue.cmd_count >= CCP_CRYPTO_MAX_QLEN) { diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 4e029b1..3d637e3 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -292,9 +292,12 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd) i = ccp->cmd_q_count; if (ccp->cmd_count >= MAX_CMD_QLEN) { - ret = -EBUSY; - if (cmd->flags & CCP_CMD_MAY_BACKLOG) + if (cmd->flags & CCP_CMD_MAY_BACKLOG) { + ret = -EBUSY; list_add_tail(&cmd->entry, &ccp->backlog); + } else { + ret = -EAGAIN; + } } else { ret = -EINPROGRESS; ccp->cmd_count++; From patchwork Tue Sep 5 12:38:42 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: 111670 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2782669qge; Tue, 5 Sep 2017 05:40:15 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4sFvTqnEfsQQTWFHDMNvRDu/yF4VSDnjrX/BQkrGCx6elKJisSwymsI7eRIAtYq1cgwWl7 X-Received: by 10.99.143.14 with SMTP id n14mr3906431pgd.339.1504615215406; Tue, 05 Sep 2017 05:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615215; cv=none; d=google.com; s=arc-20160816; b=noqKXQNovcFSoS9E9162T0iN43xw+fM0w2djxJRqufYnMozXFpREXCMT46Zes5wz5v NEUhCaZv/HLA014l5VQWcXkNDI5AiihdwNNlw8Olg4h6RjD39aQ9DL/osI8Gz8DMrKA2 2Me9tTaBB18bYqM0OS9Bc2YCrCWwrJdwlwTUFY/io5olrHcJOGsSK1ZC7bZ1p8Hf0t5s 1KAgJ+Hlhl8bJ3T34gi8J0xJlEQpmSInAqN/MZ2qnzG1vAYMNCf2hfiChv0flVhfxgfb FRhldeGIbE6P0Bg+N81HzCC2mkzEhV6juvHcua5aljNNdLneXtSBbPYIaoJOeXDOLAQ/ qY6A== 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=rECVBwVTcvYEwelGwpYfHmHc22I8S/NlkYAbjK1IAC8=; b=lazqqeTh7IggurHHmcOgljzPIaMat8+PEtSMQr4lxbY2CiWDIa5PUivadpB//Cgxp8 U806GwbJVluIPvfWmJmvlhthcxVb6+VZ/qofoa2lAScaXH5aOTGkW516GYXcS9x45MVr 60Z+B1WNv9Yw9h8J9/0KDZ3snd+Ni3mCtuFhSVph0Wu/xv99Qi16UcgWim1hfHeL8fEE rgh+mjkra2zfkv4lFPEK1MFgBTDLNYWVEOqnwdj7HemLxeXV536nk3a9k0Sm1sElxtVn mGSN2F7ZSI5fql6STjU9xz50CqfOSpDzgISRoPwp9foOiUXMGuPJ7pvod5Fg/6BH/G1g t8AA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si201847pga.495.2017.09.05.05.40.15; Tue, 05 Sep 2017 05:40:15 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751703AbdIEMkM (ORCPT + 1 other); Tue, 5 Sep 2017 08:40:12 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39050 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbdIEMkF (ORCPT ); Tue, 5 Sep 2017 08:40:05 -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 9E457164F; Tue, 5 Sep 2017 05:40:04 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6F17C3F3E1; Tue, 5 Sep 2017 05:39:54 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 03/20] net: use -EAGAIN for transient busy indication Date: Tue, 5 Sep 2017 15:38:42 +0300 Message-Id: <1504615144-29770-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Replace -EBUSY with -EAGAIN when handling transient busy indication in the absence of backlog. Signed-off-by: Gilad Ben-Yossef --- Please squash this patch with the previous one when merging upstream. --- net/ipv4/ah4.c | 2 +- net/ipv4/esp4.c | 2 +- net/ipv6/ah6.c | 2 +- net/ipv6/esp6.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) -- 2.1.4 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c index 37db44f..049cb0a 100644 --- a/net/ipv4/ah4.c +++ b/net/ipv4/ah4.c @@ -240,7 +240,7 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb) if (err == -EINPROGRESS) goto out; - if (err == -EBUSY) + if (err == -EAGAIN) err = NET_XMIT_DROP; goto out_free; } diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index b00e4a4..ff8e088 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -432,7 +432,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * case -EINPROGRESS: goto error; - case -EBUSY: + case -EAGAIN: err = NET_XMIT_DROP; break; diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c index 7802b72..ba0c145 100644 --- a/net/ipv6/ah6.c +++ b/net/ipv6/ah6.c @@ -443,7 +443,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb) if (err == -EINPROGRESS) goto out; - if (err == -EBUSY) + if (err == -EAGAIN) err = NET_XMIT_DROP; goto out_free; } diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 89910e2..1a71ee5 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -396,7 +396,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info case -EINPROGRESS: goto error; - case -EBUSY: + case -EAGAIN: err = NET_XMIT_DROP; break; From patchwork Tue Sep 5 12:38:43 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: 111671 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2782932qge; Tue, 5 Sep 2017 05:40:27 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7z2ZO739Y6HIrWCv8AU/KUDUQzQGyXv6crN96wt3pResRDscO5VCehewQJ54tA5Adeo5vx X-Received: by 10.84.233.10 with SMTP id j10mr4263751plk.134.1504615227615; Tue, 05 Sep 2017 05:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615227; cv=none; d=google.com; s=arc-20160816; b=rZdyYMnAGKbfiwD6mneCcWfjU39wzTmXeB/5xzCOrFsnbZJyJTFh2d8MKlXjUOwMoV eAd1NvrUw/GMBVkyuoFALJORdkllSMbBmVMgdSyADsRpQswVXiiQAaIrnvwlA9M9kGDH TtD6BUCJeWUOWzb7Oe/kNxYoDv+TITKSfKQwB93H8sIEGBshs2ahMcWsnIPc/mbyrtrD aTfzCsl7N2bkzOs/U5T9s0KejrV0X4YJbOJAoFtWxnDtSFPZqLU+mZ6IiT0yl9VTYKxz sSFlpT3yBKZYT7WWgxiNBQxhvwLzkfdnwWsZc9ZkO3p//IPPwOYcRmHFEVVVqLvbgi/p mGmA== 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=LqFDUW/U8XOlFhRXXYUJtIljn3rIG37gt0rwTDnyBXQ=; b=ouou+PTTlILQWXWUR/vpQljioCzUwKQJ+Rp0eyKKcYXezt8bJ26aVTKrXNaNtRCOrW RUPPI78kwgqNmMdvENatI7gI1Z6+oyFljeAr28pV7QShqwHOicv0xiT7rRpoH17fM82e +IbqfjD6lzF22QIcxDYi9mp6EcULpgb7XluALqHW6VoePOsqFL5n98SpKcxJwjQARaVf ongvru7cnBJmQFHEIiVCngdAYlk0tmmXqzbNTjbHTCJ4ceER7eJcGWwZt/9M65Vr4PTu edk+yMNRQuk8FJP3aVMra+fDsIAOwBxYeHKku5J4tb/0w8ScYsZe24DzO45jLtSAVsNo RdZQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si280280pln.619.2017.09.05.05.40.27; Tue, 05 Sep 2017 05:40:27 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751794AbdIEMkY (ORCPT + 1 other); Tue, 5 Sep 2017 08:40:24 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39102 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdIEMkU (ORCPT ); Tue, 5 Sep 2017 08:40:20 -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 29A411596; Tue, 5 Sep 2017 05:40:19 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CE043F3E1; Tue, 5 Sep 2017 05:40:09 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 04/20] crypto: remove redundant backlog checks on EBUSY Date: Tue, 5 Sep 2017 15:38:43 +0300 Message-Id: <1504615144-29770-5-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Now that -EBUSY return code only indicates backlog queueing we can safely remove the now redundant check for the CRYPTO_TFM_REQ_MAY_BACKLOG flag when -EBUSY is returned. Signed-off-by: Gilad Ben-Yossef --- crypto/ahash.c | 12 +++--------- crypto/cts.c | 6 ++---- crypto/lrw.c | 8 ++------ crypto/rsa-pkcs1pad.c | 16 ++++------------ crypto/xts.c | 8 ++------ 5 files changed, 13 insertions(+), 37 deletions(-) -- 2.1.4 diff --git a/crypto/ahash.c b/crypto/ahash.c index 5e8666e..3a35d67 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -334,9 +334,7 @@ static int ahash_op_unaligned(struct ahash_request *req, return err; err = op(req); - if (err == -EINPROGRESS || - (err == -EBUSY && (ahash_request_flags(req) & - CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err == -EINPROGRESS || err == -EBUSY) return err; ahash_restore_req(req, err); @@ -394,9 +392,7 @@ static int ahash_def_finup_finish1(struct ahash_request *req, int err) req->base.complete = ahash_def_finup_done2; err = crypto_ahash_reqtfm(req)->final(req); - if (err == -EINPROGRESS || - (err == -EBUSY && (ahash_request_flags(req) & - CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err == -EINPROGRESS || err == -EBUSY) return err; out: @@ -432,9 +428,7 @@ static int ahash_def_finup(struct ahash_request *req) return err; err = tfm->update(req); - if (err == -EINPROGRESS || - (err == -EBUSY && (ahash_request_flags(req) & - CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err == -EINPROGRESS || err == -EBUSY) return err; return ahash_def_finup_finish1(req, err); diff --git a/crypto/cts.c b/crypto/cts.c index 243f591..4773c18 100644 --- a/crypto/cts.c +++ b/crypto/cts.c @@ -136,8 +136,7 @@ static void crypto_cts_encrypt_done(struct crypto_async_request *areq, int err) goto out; err = cts_cbc_encrypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return; out: @@ -229,8 +228,7 @@ static void crypto_cts_decrypt_done(struct crypto_async_request *areq, int err) goto out; err = cts_cbc_decrypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return; out: diff --git a/crypto/lrw.c b/crypto/lrw.c index a8bfae4..695cea9 100644 --- a/crypto/lrw.c +++ b/crypto/lrw.c @@ -328,9 +328,7 @@ static int do_encrypt(struct skcipher_request *req, int err) crypto_skcipher_encrypt(subreq) ?: post_crypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && - req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return err; } @@ -380,9 +378,7 @@ static int do_decrypt(struct skcipher_request *req, int err) crypto_skcipher_decrypt(subreq) ?: post_crypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && - req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return err; } diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c index 407c64b..2908f93 100644 --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -279,9 +279,7 @@ static int pkcs1pad_encrypt(struct akcipher_request *req) req->dst, ctx->key_size - 1, req->dst_len); err = crypto_akcipher_encrypt(&req_ctx->child_req); - if (err != -EINPROGRESS && - (err != -EBUSY || - !(req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err != -EINPROGRESS && err != -EBUSY) return pkcs1pad_encrypt_sign_complete(req, err); return err; @@ -383,9 +381,7 @@ static int pkcs1pad_decrypt(struct akcipher_request *req) ctx->key_size); err = crypto_akcipher_decrypt(&req_ctx->child_req); - if (err != -EINPROGRESS && - (err != -EBUSY || - !(req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err != -EINPROGRESS && err != -EBUSY) return pkcs1pad_decrypt_complete(req, err); return err; @@ -440,9 +436,7 @@ static int pkcs1pad_sign(struct akcipher_request *req) req->dst, ctx->key_size - 1, req->dst_len); err = crypto_akcipher_sign(&req_ctx->child_req); - if (err != -EINPROGRESS && - (err != -EBUSY || - !(req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err != -EINPROGRESS && err != -EBUSY) return pkcs1pad_encrypt_sign_complete(req, err); return err; @@ -561,9 +555,7 @@ static int pkcs1pad_verify(struct akcipher_request *req) ctx->key_size); err = crypto_akcipher_verify(&req_ctx->child_req); - if (err != -EINPROGRESS && - (err != -EBUSY || - !(req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))) + if (err != -EINPROGRESS && err != -EBUSY) return pkcs1pad_verify_complete(req, err); return err; diff --git a/crypto/xts.c b/crypto/xts.c index d86c11a..af68012 100644 --- a/crypto/xts.c +++ b/crypto/xts.c @@ -269,9 +269,7 @@ static int do_encrypt(struct skcipher_request *req, int err) crypto_skcipher_encrypt(subreq) ?: post_crypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && - req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return err; } @@ -321,9 +319,7 @@ static int do_decrypt(struct skcipher_request *req, int err) crypto_skcipher_decrypt(subreq) ?: post_crypt(req); - if (err == -EINPROGRESS || - (err == -EBUSY && - req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) + if (err == -EINPROGRESS || err == -EBUSY) return err; } From patchwork Tue Sep 5 12:38:44 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: 111672 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2783216qge; Tue, 5 Sep 2017 05:40:41 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5QLozcaAlLhFUjMgz31iZY0rmDFdJsmMc3Jf8DjeIovZw5SZv84Pv6/ELM9OkyA+qWRap2 X-Received: by 10.84.129.100 with SMTP id 91mr4265613plb.198.1504615241094; Tue, 05 Sep 2017 05:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615241; cv=none; d=google.com; s=arc-20160816; b=ceXtqSIcJ/5j8dPR2oHyPpjLua1mpyXib6krWc+G4AKVXVXHY+a8QCg1YeQMRNgA3Q 5O968xS1iKrklA9bsoFi4AwrmFkfDQq7Zzc+ZTJHeFtYlp21Cgs+K5nbqdgELXJY4Skk P5cP7G7xilGaTuwsSF/XuJLN8XNlqQEpmhExPAef+sKuPXJ1yHfn3kTfgEQDeaRcmd6a yRbofGXX/DS82t5arx/ApYQlcliu0BzFOL2CffqMIL7StaM0+upf/gm0wp/jxEZHO4v6 XcAAkr16IETAL507HMUVkfD+h2htQOBBfGwzbwixKFK2pkGcbzUQMu+fsafN4bwuIM3Q uGyQ== 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=MDkCDhc9vU1uhczJZHVKCArehMUt8ZvvR7DujJSjcIk=; b=cy8QGizkYlWt+PHAcZDMUGWWPj9O3cIA7HoZ57KMQX33ATJiQ1+y8s6ds2DYn7JX8X K1KVOjj7/DFrqTsU4rEJ47C+w2W3mueGkQ2oJFDrJmAoOKt5NrzHPQ3h/xswZ0IkMGae uYup2jyssFubJzbo6k5tk9vO8+/hYPJwRwIWTXn0sA2GlFbbklKv2Ei7GPNoMaMjPwic mB/RzXDbUErft4/vYorVo69GCsw6TxGijgLc12scg/ZemaV0ey2VpK01IPQHCVbIeTBJ GpU7W80wRVKWEozE37B+BE+hb8qhVheRwsrUdC3k1gGIAFOuXCMo9PnF9fLLZoOz3ZWr t9qw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si285728plk.687.2017.09.05.05.40.40; Tue, 05 Sep 2017 05:40:41 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbdIEMki (ORCPT + 1 other); Tue, 5 Sep 2017 08:40:38 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39172 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdIEMkd (ORCPT ); Tue, 5 Sep 2017 08:40:33 -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 F40C9165C; Tue, 5 Sep 2017 05:40:32 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F19823F3E1; Tue, 5 Sep 2017 05:40:23 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 05/20] crypto: marvell/cesa: remove redundant backlog checks on EBUSY Date: Tue, 5 Sep 2017 15:38:44 +0300 Message-Id: <1504615144-29770-6-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Now that -EBUSY return code only indicates backlog queueing we can safely remove the now redundant check for the CRYPTO_TFM_REQ_MAY_BACKLOG flag when -EBUSY is returned. Signed-off-by: Gilad Ben-Yossef Acked-by: Boris Brezillon --- drivers/crypto/marvell/cesa.c | 3 +-- drivers/crypto/marvell/cesa.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) -- 2.1.4 diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c index 6e7a5c7..0c3909d 100644 --- a/drivers/crypto/marvell/cesa.c +++ b/drivers/crypto/marvell/cesa.c @@ -183,8 +183,7 @@ int mv_cesa_queue_req(struct crypto_async_request *req, spin_lock_bh(&engine->lock); ret = crypto_enqueue_request(&engine->queue, req); if ((mv_cesa_req_get_type(creq) == CESA_DMA_REQ) && - (ret == -EINPROGRESS || - (ret == -EBUSY && req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG))) + (ret == -EINPROGRESS || ret == -EBUSY)) mv_cesa_tdma_chain(engine, creq); spin_unlock_bh(&engine->lock); diff --git a/drivers/crypto/marvell/cesa.h b/drivers/crypto/marvell/cesa.h index b7872f6..63c8457 100644 --- a/drivers/crypto/marvell/cesa.h +++ b/drivers/crypto/marvell/cesa.h @@ -763,7 +763,7 @@ static inline int mv_cesa_req_needs_cleanup(struct crypto_async_request *req, * the backlog and will be processed later. There's no need to * clean it up. */ - if (ret == -EBUSY && req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG) + if (ret == -EBUSY) return false; /* Request wasn't queued, we need to clean it up */ From patchwork Tue Sep 5 12:38:45 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: 111673 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2783474qge; Tue, 5 Sep 2017 05:40:56 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7eiv4aii+mfrBZz72CaCF+Ucj6mlVZyYHCajaQGdvvhRtxcfkTAIOP/n0bxRJ/IXPHdOLJ X-Received: by 10.99.185.93 with SMTP id v29mr4043220pgo.32.1504615256493; Tue, 05 Sep 2017 05:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615256; cv=none; d=google.com; s=arc-20160816; b=HEygg7QcZa6i2z/HTag6OROlmfcPl1+65Y2rJ3HOfgilqr5JvqZ4VwF+QdCUBgnKh3 Y1hSmEXNt6wC7hdJhrez0OkXLiQhBlGL8rFup64TEyuNd/TQ0wxGM71J3BNvyZkhE7bZ IPqdvBrSvGn/Tdvuwmt9ZDWABP7bApu7m6nq6x60EdNOBF+7K8pU4NGhqrXnS+w62E6o uJbwBT3he5lCfHxeSSeWoZNAimuq0rG0Q8q65uqcO4dTz353ubvlFCc/GmxYb0BYhCvl TOkL90YemdQ8vbWdLBRk1JsVYI2qsjIuFO0CO0aCJWCJo8yjonZ+zkQjdJY04L//rLXv 0jCg== 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=IWQxhc9f+ZEDcXLqo69EmeKTP3a7hAl6VOEf3gYUOes=; b=OHPnxUDCWW7IGMlw6PqzEmtkUuqYOdubkWPKs7mzZLU8UgxpoJPNbRKMs5xRHZYqDD XWT3VN9Vc3vfxazJhDkzLOs/YYmg+cEhgnSHvva6b+4Mt98mvPHnJDPWaDb09avGYE80 t0Xn5HDQESI7AcLIqFtU6i0i+fkYsSfJr0tk/+MJVdqrGN+8yMGnaalICCro/prmvl7v CJDXAecZ9rCQPd4fIcyENfMfdyBFyYDwjdcvOULHP8AxjY0xJNBLiO8WZlxpl00SMjdj 8Gskp5BpQIDL1dRJNGKxzH9Gwd362AOjpS8n3FHC5j+t0P2VEuyr+9wG5yk08qug5Al5 K9LA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si199955pgp.482.2017.09.05.05.40.55; Tue, 05 Sep 2017 05:40:56 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751420AbdIEMky (ORCPT + 1 other); Tue, 5 Sep 2017 08:40:54 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39242 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751386AbdIEMks (ORCPT ); Tue, 5 Sep 2017 08:40:48 -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 53A76165D; Tue, 5 Sep 2017 05:40:47 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF76E3F3E1; Tue, 5 Sep 2017 05:40:37 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang , Eric Biggers , Jonathan Cameron Subject: [PATCH v8 06/20] crypto: introduce crypto wait for async op Date: Tue, 5 Sep 2017 15:38:45 +0300 Message-Id: <1504615144-29770-7-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Invoking a possibly async. crypto op and waiting for completion while correctly handling backlog processing is a common task in the crypto API implementation and outside users of it. This patch adds a generic implementation for doing so in preparation for using it across the board instead of hand rolled versions. Signed-off-by: Gilad Ben-Yossef CC: Eric Biggers CC: Jonathan Cameron --- crypto/api.c | 13 +++++++++++++ include/linux/crypto.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) -- 2.1.4 diff --git a/crypto/api.c b/crypto/api.c index 941cd4c..2a2479d 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "internal.h" LIST_HEAD(crypto_alg_list); @@ -595,5 +596,17 @@ int crypto_has_alg(const char *name, u32 type, u32 mask) } EXPORT_SYMBOL_GPL(crypto_has_alg); +void crypto_req_done(struct crypto_async_request *req, int err) +{ + struct crypto_wait *wait = req->data; + + if (err == -EINPROGRESS) + return; + + wait->err = err; + complete(&wait->completion); +} +EXPORT_SYMBOL_GPL(crypto_req_done); + MODULE_DESCRIPTION("Cryptographic core API"); MODULE_LICENSE("GPL"); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 84da997..78508ca 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -24,6 +24,7 @@ #include #include #include +#include /* * Autoloaded crypto modules should only use a prefixed name to avoid allowing @@ -468,6 +469,45 @@ struct crypto_alg { } CRYPTO_MINALIGN_ATTR; /* + * A helper struct for waiting for completion of async crypto ops + */ +struct crypto_wait { + struct completion completion; + int err; +}; + +/* + * Macro for declaring a crypto op async wait object on stack + */ +#define DECLARE_CRYPTO_WAIT(_wait) \ + struct crypto_wait _wait = { \ + COMPLETION_INITIALIZER_ONSTACK((_wait).completion), 0 } + +/* + * Async ops completion helper functioons + */ +void crypto_req_done(struct crypto_async_request *req, int err); + +static inline int crypto_wait_req(int err, struct crypto_wait *wait) +{ + switch (err) { + case -EINPROGRESS: + case -EBUSY: + wait_for_completion(&wait->completion); + reinit_completion(&wait->completion); + err = wait->err; + break; + }; + + return err; +} + +static inline void crypto_init_wait(struct crypto_wait *wait) +{ + init_completion(&wait->completion); +} + +/* * Algorithm registration interface. */ int crypto_register_alg(struct crypto_alg *alg); From patchwork Tue Sep 5 12:38:47 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: 111675 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2783938qge; Tue, 5 Sep 2017 05:41:24 -0700 (PDT) X-Google-Smtp-Source: ADKCNb50hd+v73qWypoYSULG4/dj7odqF4WZVXssT+DntZAB7d3VF2jJTnnj4piwm/SNWol501gG X-Received: by 10.101.66.205 with SMTP id l13mr3844146pgp.278.1504615284101; Tue, 05 Sep 2017 05:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615284; cv=none; d=google.com; s=arc-20160816; b=miYikhN9x+jziqCm7tsrk70e/JOgVg8w9mLr7YWwu20MJGtUF3f0WmrGR+Cn6LMRth qvg9IiEzEdiU2MkXJmF3DA4WXfunuli6X4a/JfsaV6yCRdDCz+UEtPJpYjOxNU0NJ9x0 iQ7rgrUuvspzv39dcVYSbIlGmtzYsbtc9gqH4MzFswEvvhQMfAIWGnr9dRGaR7Pqi2K4 nbbQcf4W9zbmwlleyNNZVudMuRkRex2uD+UweaxzgsoSy9pNJ1luYotkp+3SIZpfrj3+ LjbusLjrSQV/F6LXX3vHvRJzIanqEgyjIashyBjmvTxqBB1JnzUep8PNWiep3/MSecyA t7jw== 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=uVGCKHc2uD3hicn0yfC02peYpdFzwFicU6prIu8exhI=; b=Q0Qjooj63EkzIYcrFqm6X58jYMDXF9BL6op9E+mBwwYAXyiPC/ucbs77B8mw7dJNb1 oP8BacHygiH7loe2XZh4H4fc/0TJHGNAFoAL4GHta37nJ/tjGUXXi3qYOMaZxvMX68i1 jmWMNUrvjH528w4hdciqw8DbJ4FAKVkpBuinck9y96rbpeC/Yx+XtaDszd1gWiVMMDCG nvgCc+kTZ8yK7bH+E0bVJV6Y97JPlFqnAbM2i1IcgEpk07srGkMn/OGC9AGfTxlcbPQx c3cIEefHWIHiDSdqaZw7nUitwzvYbfQ/wneFK2L6tzc+supxl6lP+WzxifksS2JK8Jbe 0r7w== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6si322621plk.127.2017.09.05.05.41.23; Tue, 05 Sep 2017 05:41:24 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751456AbdIEMlT (ORCPT + 1 other); Tue, 5 Sep 2017 08:41:19 -0400 Received: from foss.arm.com ([217.140.101.70]:39330 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751386AbdIEMlQ (ORCPT ); Tue, 5 Sep 2017 08:41:16 -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 C9BDA165C; Tue, 5 Sep 2017 05:41:15 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64AED3F3E1; Tue, 5 Sep 2017 05:41:06 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 08/20] crypto: move pub key to generic async completion Date: Tue, 5 Sep 2017 15:38:47 +0300 Message-Id: <1504615144-29770-9-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org public_key_verify_signature() is starting an async crypto op and waiting for it to complete. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- crypto/asymmetric_keys/public_key.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) -- 2.1.4 diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index 3cd6e12..d916235 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -57,29 +57,13 @@ static void public_key_destroy(void *payload0, void *payload3) public_key_signature_free(payload3); } -struct public_key_completion { - struct completion completion; - int err; -}; - -static void public_key_verify_done(struct crypto_async_request *req, int err) -{ - struct public_key_completion *compl = req->data; - - if (err == -EINPROGRESS) - return; - - compl->err = err; - complete(&compl->completion); -} - /* * Verify a signature using a public key. */ int public_key_verify_signature(const struct public_key *pkey, const struct public_key_signature *sig) { - struct public_key_completion compl; + struct crypto_wait cwait; struct crypto_akcipher *tfm; struct akcipher_request *req; struct scatterlist sig_sg, digest_sg; @@ -131,20 +115,16 @@ int public_key_verify_signature(const struct public_key *pkey, sg_init_one(&digest_sg, output, outlen); akcipher_request_set_crypt(req, &sig_sg, &digest_sg, sig->s_size, outlen); - init_completion(&compl.completion); + crypto_init_wait(&cwait); akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - public_key_verify_done, &compl); + crypto_req_done, &cwait); /* Perform the verification calculation. This doesn't actually do the * verification, but rather calculates the hash expected by the * signature and returns that to us. */ - ret = crypto_akcipher_verify(req); - if ((ret == -EINPROGRESS) || (ret == -EBUSY)) { - wait_for_completion(&compl.completion); - ret = compl.err; - } + ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait); if (ret < 0) goto out_free_output; From patchwork Tue Sep 5 12:38:48 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: 111676 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2784199qge; Tue, 5 Sep 2017 05:41:39 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7eHyuuCgFvBduLpCa9s5WaHUsCCn5+OShbfZGZiIPGcobHexxQvsy+xjgYZC48fTGvWxqJ X-Received: by 10.101.91.134 with SMTP id i6mr3858292pgr.428.1504615299836; Tue, 05 Sep 2017 05:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615299; cv=none; d=google.com; s=arc-20160816; b=SXbXj7SIN/Cv0MR6DwnsdqWXgkYz9WSdr8WHX8YFJX8XkQ0xtD18HghQU98yEuc1hv Uj+1NgFQnaLdQXlfYH8vOdkWfzDpFQ/K9OPhMdlOu5DeYR8i3EHSsJZcX7lDUdTJQE4E UmWq9hw7VcJJb3ffvLYIkKNit8y2oYBTe2azJtjWdSFlJbYjYWhMVCF7lpglS0BRKlqR fpDtWV4tWoXMbJ9tcZ0jx/QCFSET7J3xllusnj8SEDkzPvyqImOnVHzCCQsxytw1xBpX 2QJjWhGfCQnfZDEDi6jXzk+iCoL8SUOAdo3ujvdrdqySTAb4ghN717fJoxLHPsMSgabD /7oA== 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=Jyzp3l5Biuc8s7RQyP5tM9iBa13E5UvxpKvqN+OK6DE=; b=ZTTlMGgGgH2HSJRJ0qOcpREuTlWDfaB95TXEhu+VLYTQlliuQK4ueqShn2C+YXGLtH 6IEs/+tXescL8fvlAXXQkospBRLhIQr8ovk4kkGJeIQZpaCqS3L1ijMPmfUClhZM8Tic jjKr9U5Df+QRyQHnsByqJ5YFER8EZkOfyLlACeXJIinSB6K5rejkB0G5noOfCRxVTGpB NwVxi8iycg8Yn+eqqrz3Ausfeb/fdvuy/yw5rbhiHVrjelUHX+2AUSovJ6fFTzG6S4zh jmM+KFUTA/2HjsFe7IDek8mXGyfvTJVgguqEYQOT0bmZFxPGDtFELtYSl7evoc3En2lq dDOQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si258947pfy.247.2017.09.05.05.41.39; Tue, 05 Sep 2017 05:41:39 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751980AbdIEMlg (ORCPT + 1 other); Tue, 5 Sep 2017 08:41:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39404 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751386AbdIEMld (ORCPT ); Tue, 5 Sep 2017 08:41:33 -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 F2F70165D; Tue, 5 Sep 2017 05:41:31 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 424893F3E1; Tue, 5 Sep 2017 05:41:20 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 09/20] crypto: move drbg to generic async completion Date: Tue, 5 Sep 2017 15:38:48 +0300 Message-Id: <1504615144-29770-10-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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 | 36 +++++++++--------------------------- include/crypto/drbg.h | 3 +-- 2 files changed, 10 insertions(+), 29 deletions(-) -- 2.1.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index 633a88e..c522251 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; @@ -1691,7 +1681,7 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg) return PTR_ERR(sk_tfm); } drbg->ctr_handle = sk_tfm; - init_completion(&drbg->ctr_completion); + crypto_init_wait(&drbg->ctr_wait); req = skcipher_request_alloc(sk_tfm, GFP_KERNEL); if (!req) { @@ -1700,8 +1690,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, @@ -1762,21 +1753,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? */ From patchwork Tue Sep 5 12:38:49 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: 111677 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2784469qge; Tue, 5 Sep 2017 05:41:54 -0700 (PDT) X-Google-Smtp-Source: ADKCNb67cKcZFrWLoCSdf7oLfsPw6u+XCwDRPsWSPXDP0dxpoIQ5iAOP7cfoYB2u8lDK0i+sICgt X-Received: by 10.84.241.201 with SMTP id t9mr4110133plm.61.1504615314474; Tue, 05 Sep 2017 05:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615314; cv=none; d=google.com; s=arc-20160816; b=eqXtQt7iTq0MKiNnFhQXomLd2yv19rKIqsoF8QTaSiBak0cOfkArrx2M+umAdYIi00 vXyEpTOM5wS7P67Ecx2IfrBbJEAABlXMRjgWA0SuMomLdMTDfI0ElJ0zcWlCHM+KZNw1 6zMJ591/k/obguVL+EPeo5Kyn6jcrF+irOrNMD2VUsaGfsUdDZKIAo+tm5CDifoVWow1 gfusDvWfX0ANIFwO38i9I+tcAcup+Qb8W7TfdtNxOQXRTmwKFZXOH4XZG439Gvo8LaDg 6+xc/ksaj3TeU69pszJoyIkdMxdwMItemrpkKelltxkcdquYisrrZuKqFShBHcDfX9My 4z5Q== 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=yGaAHjHUMBmQzH3ic2oX8wNfseqXS3eodE5CNvqrLCs=; b=QwnKl3vDIjSMKTGnbZ7Yad2S4JsiickAQd7J0reosjOppVY8pqWyT0rRi9I5GctUU9 RlPCOpy0qyLI554wNOhRUBETK58WgkhIp3q7hIIi1fPEphxmHYGONlE2IIf1rq4ai42F E5cH8SwqhtxR3WwPYczv+4p1+GQ1o+jg78xNvHTdJMNqcKh9wznLpmy5cNnmm6p4DMZI /ZAYJrQVwURdyCl3x0kmhfoRPKM9lzxYfhJ9WkKE0DDVNq+NJo1HopU49vK8Tuys1QE5 22gapYuop3xL0AnLi1YqMSH/dhlfO6jIqUaJd/SWH3t/U7x1fmi32JlPetaX63fHV2km epjg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si291407plk.638.2017.09.05.05.41.54; Tue, 05 Sep 2017 05:41:54 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751388AbdIEMlw (ORCPT + 1 other); Tue, 5 Sep 2017 08:41:52 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39464 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbdIEMls (ORCPT ); Tue, 5 Sep 2017 08:41:48 -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 5AD961688; Tue, 5 Sep 2017 05:41:47 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 14A3D3F3E1; Tue, 5 Sep 2017 05:41:36 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 10/20] crypto: move gcm to generic async completion Date: Tue, 5 Sep 2017 15:38:49 +0300 Message-Id: <1504615144-29770-11-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org gcm is starting an async. crypto op and waiting for it complete. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- crypto/gcm.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) -- 2.1.4 diff --git a/crypto/gcm.c b/crypto/gcm.c index 3841b5e..fb923a5 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -16,7 +16,6 @@ #include #include #include "internal.h" -#include #include #include #include @@ -78,11 +77,6 @@ struct crypto_gcm_req_priv_ctx { } u; }; -struct crypto_gcm_setkey_result { - int err; - struct completion completion; -}; - static struct { u8 buf[16]; struct scatterlist sg; @@ -98,17 +92,6 @@ static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx( return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); } -static void crypto_gcm_setkey_done(struct crypto_async_request *req, int err) -{ - struct crypto_gcm_setkey_result *result = req->data; - - if (err == -EINPROGRESS) - return; - - result->err = err; - complete(&result->completion); -} - static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { @@ -119,7 +102,7 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, be128 hash; u8 iv[16]; - struct crypto_gcm_setkey_result result; + struct crypto_wait wait; struct scatterlist sg[1]; struct skcipher_request req; @@ -140,21 +123,18 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, if (!data) return -ENOMEM; - init_completion(&data->result.completion); + crypto_init_wait(&data->wait); sg_init_one(data->sg, &data->hash, sizeof(data->hash)); skcipher_request_set_tfm(&data->req, ctr); skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG, - crypto_gcm_setkey_done, - &data->result); + crypto_req_done, + &data->wait); skcipher_request_set_crypt(&data->req, data->sg, data->sg, sizeof(data->hash), data->iv); - err = crypto_skcipher_encrypt(&data->req); - if (err == -EINPROGRESS || err == -EBUSY) { - wait_for_completion(&data->result.completion); - err = data->result.err; - } + err = crypto_wait_req(crypto_skcipher_encrypt(&data->req), + &data->wait); if (err) goto out; From patchwork Tue Sep 5 12:38:50 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: 111678 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2784752qge; Tue, 5 Sep 2017 05:42:09 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7JXlHcai5F56mSPg7ZRIp4U++dYxmiQmQqfRnNlClcmckrrEZEnUnMfGiFm4B+syFf0ZHI X-Received: by 10.84.234.16 with SMTP id m16mr4298100plk.391.1504615329882; Tue, 05 Sep 2017 05:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615329; cv=none; d=google.com; s=arc-20160816; b=acQYzYiBnowhuNu4ETFbaV5b+ziBopBDjarJQe8+y0gqioZih6eiNoJt4ssu2mED5Y pCyho7N6ChOneiROLV/dDhlDqZewDLy8ypSKuccamdAiEoUKAuNunjn1sTcQPADE0Vzz L34HRnyNkVx2vNsZXagMKdYt/1Yq+YUEg66LUCo7vdq2ujm0Q3T2OU5dxe9PJTzl1y46 Qelb5S9N9R40Y4YTlgJivDgOBYaB9PFJH3QPfX1m15uOvFoK/5L10ks5YjSlnXQIsp2l 8/GNKrLvLfhtufMBgQ0oO+gtq2pczFxM7RfzyYTDrDU/kjlzUb3bQqn9ZdYVr1JwHmSv 7Anw== 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=pkoDR6LZUpHhMuvTWQpvlrjKYcV9jpyFfFIoYfQy4rA=; b=OkGUy1BRaH2riKtmUDLxtnLWdOJpGa66BA/xklSWTMpOrHM97emhmKx0+hhPwlZdWH 9kUJeK7Whfze2br/GrzucBBzK2wydDw9VIfhQkHhjVusLN5ZmnpUhd2bzfxpZ8tC3EZa FzQBE0gAnavxlYEazqLUrttJ5t+UKyXbz0Z9ODk1hzW2xLmKNNVLlr+9vqSqxJSmQMBL IqUQajEQmEkZ03LQDS4wT2eseBx7ztjh92tS1B/FXnu6REfuqqqm/JO5hWb4DAExYuqn RYlDywkmgtAPGWfQcT5MJrRrlX8X+g9ClYzSZpkYimpB61ZJ0MC8KkLMLqILZTI4i4kC gtYQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 83si242747pfa.424.2017.09.05.05.42.09; Tue, 05 Sep 2017 05:42:09 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751706AbdIEMmH (ORCPT + 1 other); Tue, 5 Sep 2017 08:42:07 -0400 Received: from foss.arm.com ([217.140.101.70]:39516 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbdIEMmC (ORCPT ); Tue, 5 Sep 2017 08:42:02 -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 BF2141684; Tue, 5 Sep 2017 05:42:01 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2ABBE3F3E1; Tue, 5 Sep 2017 05:41:51 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 11/20] crypto: move testmgr to generic async completion Date: Tue, 5 Sep 2017 15:38:50 +0300 Message-Id: <1504615144-29770-12-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org testmgr is starting async. crypto ops and waiting for them to complete. Move it over to generic code doing the same. This also provides a test of the generic crypto async. wait code. Signed-off-by: Gilad Ben-Yossef --- crypto/testmgr.c | 204 ++++++++++++++++++------------------------------------- 1 file changed, 66 insertions(+), 138 deletions(-) -- 2.1.4 diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 8a124d3..af968f4 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -76,11 +76,6 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask) #define ENCRYPT 1 #define DECRYPT 0 -struct tcrypt_result { - struct completion completion; - int err; -}; - struct aead_test_suite { struct { const struct aead_testvec *vecs; @@ -155,17 +150,6 @@ static void hexdump(unsigned char *buf, unsigned int len) buf, len, false); } -static void tcrypt_complete(struct crypto_async_request *req, int err) -{ - struct tcrypt_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - static int testmgr_alloc_buf(char *buf[XBUFSIZE]) { int i; @@ -193,20 +177,10 @@ static void testmgr_free_buf(char *buf[XBUFSIZE]) free_page((unsigned long)buf[i]); } -static int wait_async_op(struct tcrypt_result *tr, int ret) -{ - if (ret == -EINPROGRESS || ret == -EBUSY) { - wait_for_completion(&tr->completion); - reinit_completion(&tr->completion); - ret = tr->err; - } - return ret; -} - static int ahash_partial_update(struct ahash_request **preq, struct crypto_ahash *tfm, const struct hash_testvec *template, void *hash_buff, int k, int temp, struct scatterlist *sg, - const char *algo, char *result, struct tcrypt_result *tresult) + const char *algo, char *result, struct crypto_wait *wait) { char *state; struct ahash_request *req; @@ -236,7 +210,7 @@ static int ahash_partial_update(struct ahash_request **preq, } ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, tresult); + crypto_req_done, wait); memcpy(hash_buff, template->plaintext + temp, template->tap[k]); @@ -247,7 +221,7 @@ static int ahash_partial_update(struct ahash_request **preq, pr_err("alg: hash: Failed to import() for %s\n", algo); goto out; } - ret = wait_async_op(tresult, crypto_ahash_update(req)); + ret = crypto_wait_req(crypto_ahash_update(req), wait); if (ret) goto out; *preq = req; @@ -272,7 +246,7 @@ static int __test_hash(struct crypto_ahash *tfm, char *result; char *key; struct ahash_request *req; - struct tcrypt_result tresult; + struct crypto_wait wait; void *hash_buff; char *xbuf[XBUFSIZE]; int ret = -ENOMEM; @@ -286,7 +260,7 @@ static int __test_hash(struct crypto_ahash *tfm, if (testmgr_alloc_buf(xbuf)) goto out_nobuf; - init_completion(&tresult.completion); + crypto_init_wait(&wait); req = ahash_request_alloc(tfm, GFP_KERNEL); if (!req) { @@ -295,7 +269,7 @@ static int __test_hash(struct crypto_ahash *tfm, goto out_noreq; } ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &tresult); + crypto_req_done, &wait); j = 0; for (i = 0; i < tcount; i++) { @@ -335,26 +309,26 @@ static int __test_hash(struct crypto_ahash *tfm, ahash_request_set_crypt(req, sg, result, template[i].psize); if (use_digest) { - ret = wait_async_op(&tresult, crypto_ahash_digest(req)); + ret = crypto_wait_req(crypto_ahash_digest(req), &wait); if (ret) { pr_err("alg: hash: digest failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } } else { - ret = wait_async_op(&tresult, crypto_ahash_init(req)); + ret = crypto_wait_req(crypto_ahash_init(req), &wait); if (ret) { pr_err("alg: hash: init failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } - ret = wait_async_op(&tresult, crypto_ahash_update(req)); + ret = crypto_wait_req(crypto_ahash_update(req), &wait); if (ret) { pr_err("alg: hash: update failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } - ret = wait_async_op(&tresult, crypto_ahash_final(req)); + ret = crypto_wait_req(crypto_ahash_final(req), &wait); if (ret) { pr_err("alg: hash: final failed on test %d " "for %s: ret=%d\n", j, algo, -ret); @@ -420,22 +394,10 @@ static int __test_hash(struct crypto_ahash *tfm, } ahash_request_set_crypt(req, sg, result, template[i].psize); - ret = crypto_ahash_digest(req); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&tresult.completion); - reinit_completion(&tresult.completion); - ret = tresult.err; - if (!ret) - break; - /* fall through */ - default: - printk(KERN_ERR "alg: hash: digest failed " - "on chunking test %d for %s: " - "ret=%d\n", j, algo, -ret); + ret = crypto_wait_req(crypto_ahash_digest(req), &wait); + if (ret) { + pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n", + j, algo, -ret); goto out; } @@ -486,13 +448,13 @@ static int __test_hash(struct crypto_ahash *tfm, } ahash_request_set_crypt(req, sg, result, template[i].tap[0]); - ret = wait_async_op(&tresult, crypto_ahash_init(req)); + ret = crypto_wait_req(crypto_ahash_init(req), &wait); if (ret) { pr_err("alg: hash: init failed on test %d for %s: ret=%d\n", j, algo, -ret); goto out; } - ret = wait_async_op(&tresult, crypto_ahash_update(req)); + ret = crypto_wait_req(crypto_ahash_update(req), &wait); if (ret) { pr_err("alg: hash: update failed on test %d for %s: ret=%d\n", j, algo, -ret); @@ -503,7 +465,7 @@ static int __test_hash(struct crypto_ahash *tfm, for (k = 1; k < template[i].np; k++) { ret = ahash_partial_update(&req, tfm, &template[i], hash_buff, k, temp, &sg[0], algo, result, - &tresult); + &wait); if (ret) { pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n", j, algo, -ret); @@ -511,7 +473,7 @@ static int __test_hash(struct crypto_ahash *tfm, } temp += template[i].tap[k]; } - ret = wait_async_op(&tresult, crypto_ahash_final(req)); + ret = crypto_wait_req(crypto_ahash_final(req), &wait); if (ret) { pr_err("alg: hash: final failed on test %d for %s: ret=%d\n", j, algo, -ret); @@ -580,7 +542,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, struct scatterlist *sg; struct scatterlist *sgout; const char *e, *d; - struct tcrypt_result result; + struct crypto_wait wait; unsigned int authsize, iv_len; void *input; void *output; @@ -619,7 +581,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, else e = "decryption"; - init_completion(&result.completion); + crypto_init_wait(&wait); req = aead_request_alloc(tfm, GFP_KERNEL); if (!req) { @@ -629,7 +591,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, } aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); iv_len = crypto_aead_ivsize(tfm); @@ -709,7 +671,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc, aead_request_set_ad(req, template[i].alen); - ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); + ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) + : crypto_aead_decrypt(req), &wait); switch (ret) { case 0: @@ -722,13 +685,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc, goto out; } break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&result.completion); - reinit_completion(&result.completion); - ret = result.err; - if (!ret) - break; case -EBADMSG: if (template[i].novrfy) /* verification failure was expected */ @@ -866,7 +822,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc, aead_request_set_ad(req, template[i].alen); - ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); + ret = crypto_wait_req(enc ? crypto_aead_encrypt(req) + : crypto_aead_decrypt(req), &wait); switch (ret) { case 0: @@ -879,13 +836,6 @@ static int __test_aead(struct crypto_aead *tfm, int enc, goto out; } break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&result.completion); - reinit_completion(&result.completion); - ret = result.err; - if (!ret) - break; case -EBADMSG: if (template[i].novrfy) /* verification failure was expected */ @@ -1083,7 +1033,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, struct scatterlist sg[8]; struct scatterlist sgout[8]; const char *e, *d; - struct tcrypt_result result; + struct crypto_wait wait; void *data; char iv[MAX_IVLEN]; char *xbuf[XBUFSIZE]; @@ -1107,7 +1057,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, else e = "decryption"; - init_completion(&result.completion); + crypto_init_wait(&wait); req = skcipher_request_alloc(tfm, GFP_KERNEL); if (!req) { @@ -1117,7 +1067,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); j = 0; for (i = 0; i < tcount; i++) { @@ -1164,21 +1114,10 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, template[i].ilen, iv); - ret = enc ? crypto_skcipher_encrypt(req) : - crypto_skcipher_decrypt(req); + ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) : + crypto_skcipher_decrypt(req), &wait); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&result.completion); - reinit_completion(&result.completion); - ret = result.err; - if (!ret) - break; - /* fall through */ - default: + if (ret) { pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", d, e, j, algo, -ret); goto out; @@ -1272,21 +1211,10 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, template[i].ilen, iv); - ret = enc ? crypto_skcipher_encrypt(req) : - crypto_skcipher_decrypt(req); + ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) : + crypto_skcipher_decrypt(req), &wait); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&result.completion); - reinit_completion(&result.completion); - ret = result.err; - if (!ret) - break; - /* fall through */ - default: + if (ret) { pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", d, e, j, algo, -ret); goto out; @@ -1462,7 +1390,7 @@ static int test_acomp(struct crypto_acomp *tfm, int ret; struct scatterlist src, dst; struct acomp_req *req; - struct tcrypt_result result; + struct crypto_wait wait; output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); if (!output) @@ -1486,7 +1414,7 @@ static int test_acomp(struct crypto_acomp *tfm, } memset(output, 0, dlen); - init_completion(&result.completion); + crypto_init_wait(&wait); sg_init_one(&src, input_vec, ilen); sg_init_one(&dst, output, dlen); @@ -1501,9 +1429,9 @@ static int test_acomp(struct crypto_acomp *tfm, acomp_request_set_params(req, &src, &dst, ilen, dlen); acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); - ret = wait_async_op(&result, crypto_acomp_compress(req)); + ret = crypto_wait_req(crypto_acomp_compress(req), &wait); if (ret) { pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", i + 1, algo, -ret); @@ -1516,10 +1444,10 @@ static int test_acomp(struct crypto_acomp *tfm, dlen = COMP_BUF_SIZE; sg_init_one(&src, output, ilen); sg_init_one(&dst, decomp_out, dlen); - init_completion(&result.completion); + crypto_init_wait(&wait); acomp_request_set_params(req, &src, &dst, ilen, dlen); - ret = wait_async_op(&result, crypto_acomp_decompress(req)); + ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); if (ret) { pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", i + 1, algo, -ret); @@ -1563,7 +1491,7 @@ static int test_acomp(struct crypto_acomp *tfm, } memset(output, 0, dlen); - init_completion(&result.completion); + crypto_init_wait(&wait); sg_init_one(&src, input_vec, ilen); sg_init_one(&dst, output, dlen); @@ -1578,9 +1506,9 @@ static int test_acomp(struct crypto_acomp *tfm, acomp_request_set_params(req, &src, &dst, ilen, dlen); acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); - ret = wait_async_op(&result, crypto_acomp_decompress(req)); + ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); if (ret) { pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n", i + 1, algo, -ret); @@ -2000,7 +1928,7 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, void *a_public = NULL; void *a_ss = NULL; void *shared_secret = NULL; - struct tcrypt_result result; + struct crypto_wait wait; unsigned int out_len_max; int err = -ENOMEM; struct scatterlist src, dst; @@ -2009,7 +1937,7 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, if (!req) return err; - init_completion(&result.completion); + crypto_init_wait(&wait); err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size); if (err < 0) @@ -2027,10 +1955,10 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, sg_init_one(&dst, output_buf, out_len_max); kpp_request_set_output(req, &dst, out_len_max); kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); /* Compute party A's public key */ - err = wait_async_op(&result, crypto_kpp_generate_public_key(req)); + err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait); if (err) { pr_err("alg: %s: Party A: generate public key test failed. err %d\n", alg, err); @@ -2069,8 +1997,8 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, kpp_request_set_input(req, &src, vec->b_public_size); kpp_request_set_output(req, &dst, out_len_max); kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); - err = wait_async_op(&result, crypto_kpp_compute_shared_secret(req)); + crypto_req_done, &wait); + err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait); if (err) { pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n", alg, err); @@ -2100,9 +2028,9 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, kpp_request_set_input(req, &src, vec->expected_a_public_size); kpp_request_set_output(req, &dst, out_len_max); kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); - err = wait_async_op(&result, - crypto_kpp_compute_shared_secret(req)); + crypto_req_done, &wait); + err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), + &wait); if (err) { pr_err("alg: %s: Party B: compute shared secret failed. err %d\n", alg, err); @@ -2179,7 +2107,7 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, struct akcipher_request *req; void *outbuf_enc = NULL; void *outbuf_dec = NULL; - struct tcrypt_result result; + struct crypto_wait wait; unsigned int out_len_max, out_len = 0; int err = -ENOMEM; struct scatterlist src, dst, src_tab[2]; @@ -2191,7 +2119,7 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, if (!req) goto free_xbuf; - init_completion(&result.completion); + crypto_init_wait(&wait); if (vecs->public_key_vec) err = crypto_akcipher_set_pub_key(tfm, vecs->key, @@ -2220,13 +2148,13 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size, out_len_max); akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); - err = wait_async_op(&result, vecs->siggen_sigver_test ? - /* Run asymmetric signature generation */ - crypto_akcipher_sign(req) : - /* Run asymmetric encrypt */ - crypto_akcipher_encrypt(req)); + err = crypto_wait_req(vecs->siggen_sigver_test ? + /* Run asymmetric signature generation */ + crypto_akcipher_sign(req) : + /* Run asymmetric encrypt */ + crypto_akcipher_encrypt(req), &wait); if (err) { pr_err("alg: akcipher: encrypt test failed. err %d\n", err); goto free_all; @@ -2261,14 +2189,14 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, sg_init_one(&src, xbuf[0], vecs->c_size); sg_init_one(&dst, outbuf_dec, out_len_max); - init_completion(&result.completion); + crypto_init_wait(&wait); akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max); - err = wait_async_op(&result, vecs->siggen_sigver_test ? - /* Run asymmetric signature verification */ - crypto_akcipher_verify(req) : - /* Run asymmetric decrypt */ - crypto_akcipher_decrypt(req)); + err = crypto_wait_req(vecs->siggen_sigver_test ? + /* Run asymmetric signature verification */ + crypto_akcipher_verify(req) : + /* Run asymmetric decrypt */ + crypto_akcipher_decrypt(req), &wait); if (err) { pr_err("alg: akcipher: decrypt test failed. err %d\n", err); goto free_all; From patchwork Tue Sep 5 12:38: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: 111679 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2785059qge; Tue, 5 Sep 2017 05:42:25 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7iy+dIocfP+eiVVnS+MWOeZE0T70UL7rVh9H72VOdaw7D82l3CAMaMF0ky13W75MRxY+1d X-Received: by 10.84.216.69 with SMTP id f5mr4413978plj.118.1504615345702; Tue, 05 Sep 2017 05:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615345; cv=none; d=google.com; s=arc-20160816; b=fqj//leeciNdJoNUvN4176BAnOVeW+MdK+O3/dwp+ZMiVqzx0xUHUZN5Xu1D873Rd+ GxwBNnuDbvPej2UMoLtaYa4L1ChGtVeHR0G4YoWLmoy00cOqao43vWGfrBvoJnisn5D2 3VPl+VaGX1eWTtaL/M1yoIKFQhG+4Hk0DDp64CjILEV6m2g2W1K5bUYkSM7kHc5mqk1X bUIxAduyRkAHBxk8CSN/n83uc78wAToFhg1cirfKqqaFSIYgO+zaybcy4/eyN+swRVGz NyerAnslp9JDMQe3yMRo8bC7iv5q9AJce5JFmWzUDYiD0BoMy7HRgqVwTtUX20F26lNy O2Wg== 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=IzYFe3sglr0ngmngCQH4PSPm4Y4NcLQNqcSqGuDD/3k=; b=ne9UC/qLlKmeulxf2Zes3IKBIM3cCfpeYYf/vEm/7hTY+Yo5GW+jr2298hBW+LbJFS ckB045ZW+2wAshS7qUrpoaR9igT7Y8ovg2V7tC+++chKdXf/8QzbFWyYxAH9FFQ9w7S1 cvV6vs6zydkR1Jth7EDAQ5r+7HqQkI3GuCdzQKepj0w/NbRvLE61pa32UMxN5pi6kObw Lj+hzo+hJtMRrH+1TMNWIEVzo0SBbSpB7iaxBqrLFdZ1+i234yBwo7ZBTC/FrtyurhPn ZKkI62Fn4cdBGF7u3Nv2OI8l6I58lKBK05JfuLeK7CWlYpzdgOJUBMDvZ4z5/CZiZEw7 djdQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si297443pll.406.2017.09.05.05.42.25; Tue, 05 Sep 2017 05:42:25 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751916AbdIEMmV (ORCPT + 1 other); Tue, 5 Sep 2017 08:42:21 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39592 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbdIEMmR (ORCPT ); Tue, 5 Sep 2017 08:42:17 -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 5D5BF1688; Tue, 5 Sep 2017 05:42:16 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 83E0D3F3E1; Tue, 5 Sep 2017 05:42:06 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 12/20] fscrypt: move to generic async completion Date: Tue, 5 Sep 2017 15:38:51 +0300 Message-Id: <1504615144-29770-13-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org fscrypt starts several async. crypto ops and waiting for them to complete. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- fs/crypto/crypto.c | 28 ++++------------------------ fs/crypto/fname.c | 36 ++++++------------------------------ fs/crypto/fscrypt_private.h | 10 ---------- fs/crypto/keyinfo.c | 21 +++------------------ 4 files changed, 13 insertions(+), 82 deletions(-) -- 2.1.4 diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index c7835df..80a3cad 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -126,21 +126,6 @@ struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, gfp_t gfp_flags) } EXPORT_SYMBOL(fscrypt_get_ctx); -/** - * page_crypt_complete() - completion callback for page crypto - * @req: The asynchronous cipher request context - * @res: The result of the cipher operation - */ -static void page_crypt_complete(struct crypto_async_request *req, int res) -{ - struct fscrypt_completion_result *ecr = req->data; - - if (res == -EINPROGRESS) - return; - ecr->res = res; - complete(&ecr->completion); -} - int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw, u64 lblk_num, struct page *src_page, struct page *dest_page, unsigned int len, @@ -151,7 +136,7 @@ int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw, u8 padding[FS_IV_SIZE - sizeof(__le64)]; } iv; struct skcipher_request *req = NULL; - DECLARE_FS_COMPLETION_RESULT(ecr); + DECLARE_CRYPTO_WAIT(wait); struct scatterlist dst, src; struct fscrypt_info *ci = inode->i_crypt_info; struct crypto_skcipher *tfm = ci->ci_ctfm; @@ -179,7 +164,7 @@ int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw, skcipher_request_set_callback( req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - page_crypt_complete, &ecr); + crypto_req_done, &wait); sg_init_table(&dst, 1); sg_set_page(&dst, dest_page, len, offs); @@ -187,14 +172,9 @@ int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw, sg_set_page(&src, src_page, len, offs); skcipher_request_set_crypt(req, &src, &dst, len, &iv); if (rw == FS_DECRYPT) - res = crypto_skcipher_decrypt(req); + res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait); else - res = crypto_skcipher_encrypt(req); - if (res == -EINPROGRESS || res == -EBUSY) { - BUG_ON(req->base.data != &ecr); - wait_for_completion(&ecr.completion); - res = ecr.res; - } + res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); skcipher_request_free(req); if (res) { printk_ratelimited(KERN_ERR diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index ad9f814..a80a0d3 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -15,21 +15,6 @@ #include "fscrypt_private.h" /** - * fname_crypt_complete() - completion callback for filename crypto - * @req: The asynchronous cipher request context - * @res: The result of the cipher operation - */ -static void fname_crypt_complete(struct crypto_async_request *req, int res) -{ - struct fscrypt_completion_result *ecr = req->data; - - if (res == -EINPROGRESS) - return; - ecr->res = res; - complete(&ecr->completion); -} - -/** * fname_encrypt() - encrypt a filename * * The caller must have allocated sufficient memory for the @oname string. @@ -40,7 +25,7 @@ static int fname_encrypt(struct inode *inode, const struct qstr *iname, struct fscrypt_str *oname) { struct skcipher_request *req = NULL; - DECLARE_FS_COMPLETION_RESULT(ecr); + DECLARE_CRYPTO_WAIT(wait); struct fscrypt_info *ci = inode->i_crypt_info; struct crypto_skcipher *tfm = ci->ci_ctfm; int res = 0; @@ -76,17 +61,12 @@ static int fname_encrypt(struct inode *inode, } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - fname_crypt_complete, &ecr); + crypto_req_done, &wait); sg_init_one(&sg, oname->name, cryptlen); skcipher_request_set_crypt(req, &sg, &sg, cryptlen, iv); /* Do the encryption */ - res = crypto_skcipher_encrypt(req); - if (res == -EINPROGRESS || res == -EBUSY) { - /* Request is being completed asynchronously; wait for it */ - wait_for_completion(&ecr.completion); - res = ecr.res; - } + res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); skcipher_request_free(req); if (res < 0) { printk_ratelimited(KERN_ERR @@ -110,7 +90,7 @@ static int fname_decrypt(struct inode *inode, struct fscrypt_str *oname) { struct skcipher_request *req = NULL; - DECLARE_FS_COMPLETION_RESULT(ecr); + DECLARE_CRYPTO_WAIT(wait); struct scatterlist src_sg, dst_sg; struct fscrypt_info *ci = inode->i_crypt_info; struct crypto_skcipher *tfm = ci->ci_ctfm; @@ -131,7 +111,7 @@ static int fname_decrypt(struct inode *inode, } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - fname_crypt_complete, &ecr); + crypto_req_done, &wait); /* Initialize IV */ memset(iv, 0, FS_CRYPTO_BLOCK_SIZE); @@ -140,11 +120,7 @@ static int fname_decrypt(struct inode *inode, sg_init_one(&src_sg, iname->name, iname->len); sg_init_one(&dst_sg, oname->name, oname->len); skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv); - res = crypto_skcipher_decrypt(req); - if (res == -EINPROGRESS || res == -EBUSY) { - wait_for_completion(&ecr.completion); - res = ecr.res; - } + res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait); skcipher_request_free(req); if (res < 0) { printk_ratelimited(KERN_ERR diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index a1d5021..c0f1881 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -69,16 +69,6 @@ typedef enum { #define FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001 #define FS_CTX_HAS_BOUNCE_BUFFER_FL 0x00000002 -struct fscrypt_completion_result { - struct completion completion; - int res; -}; - -#define DECLARE_FS_COMPLETION_RESULT(ecr) \ - struct fscrypt_completion_result ecr = { \ - COMPLETION_INITIALIZER_ONSTACK((ecr).completion), 0 } - - /* crypto.c */ extern int fscrypt_initialize(unsigned int cop_flags); extern struct workqueue_struct *fscrypt_read_workqueue; diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c index 018c588..3c84cac 100644 --- a/fs/crypto/keyinfo.c +++ b/fs/crypto/keyinfo.c @@ -17,17 +17,6 @@ static struct crypto_shash *essiv_hash_tfm; -static void derive_crypt_complete(struct crypto_async_request *req, int rc) -{ - struct fscrypt_completion_result *ecr = req->data; - - if (rc == -EINPROGRESS) - return; - - ecr->res = rc; - complete(&ecr->completion); -} - /** * derive_key_aes() - Derive a key using AES-128-ECB * @deriving_key: Encryption key used for derivation. @@ -42,7 +31,7 @@ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE], { int res = 0; struct skcipher_request *req = NULL; - DECLARE_FS_COMPLETION_RESULT(ecr); + DECLARE_CRYPTO_WAIT(wait); struct scatterlist src_sg, dst_sg; struct crypto_skcipher *tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0); @@ -59,7 +48,7 @@ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE], } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - derive_crypt_complete, &ecr); + crypto_req_done, &wait); res = crypto_skcipher_setkey(tfm, deriving_key, FS_AES_128_ECB_KEY_SIZE); if (res < 0) @@ -69,11 +58,7 @@ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE], sg_init_one(&dst_sg, derived_raw_key, source_key->size); skcipher_request_set_crypt(req, &src_sg, &dst_sg, source_key->size, NULL); - res = crypto_skcipher_encrypt(req); - if (res == -EINPROGRESS || res == -EBUSY) { - wait_for_completion(&ecr.completion); - res = ecr.res; - } + res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); out: skcipher_request_free(req); crypto_free_skcipher(tfm); From patchwork Tue Sep 5 12:38:53 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: 111681 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2785574qge; Tue, 5 Sep 2017 05:42:54 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5D7iwxU8Rq6Jc2VYbZjbFfrxCZh1/Ixz25t9ZyYIEVxIFBQI2g3h+wAYa66K6YSuUwzAvU X-Received: by 10.101.74.207 with SMTP id c15mr3814614pgu.227.1504615374761; Tue, 05 Sep 2017 05:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615374; cv=none; d=google.com; s=arc-20160816; b=WIVqFYloTNLoA1erSV14qHYDT4qK7xeqgG7rrqeFb1w9wViT/2aT7IPtKMWWmCnC40 JWuKz9He1fsPF2eGnRiigHw/emMMDQtCURwdstIrOzz7sFfd8DZVcq/nvG5sSQkZOzLM 7N5MVwKEyANRn1VvpNH51ZKwNi5GuhoEWMxZTmtK+xjBdAC5ssxhyCMioAyd3Qp4/LDg 3v0afMzLUyrsr2thcpDaHzUZMC0knW6WrPU0P2+X1vjxxgXwtfxXt94Fm2irkZ313fhv PBzRO934kHkyRzvxNJUHcMywjjEN306H33mNnzUBCiKtwhIhrArMezCcvVoFO9oCytck cFJw== 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=V5+pdMVaV58CXee7eUr8X777D/mUlNlOwg1k0fJk5Wk=; b=Ec/69Vm3fc853bKV6eh1vEyIhbAdZHNO+Ulzi1/JAgMJrHOohT3ddIclfcUpPPhtuZ DgORePR2HtN3sB96SGmbfehR/ey1RaXpCasJr3x2TAH5pvo+tlrS6nM/JcJPXOfoik6m RZw0jnemNNuEz3lZrjK5YQftFG2Av229DcTR7TJQkbx5vhcscA3pl6H76UntAJAAU73z 91T7ClpoZjfQcSe5B/XAIzxAgHrZrjH7G/PkMfjSUrr/6obrp/RSxjfGRy+J2D+rv4ZN ABvITQtQubvA7nw3X08rkbIn/Os1ohrJ7DCxHxJ01RwRCIg+8J2RePnpKc1h7awYge++ 3RNg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si283078plb.713.2017.09.05.05.42.54; Tue, 05 Sep 2017 05:42:54 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751635AbdIEMmv (ORCPT + 1 other); Tue, 5 Sep 2017 08:42:51 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39688 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbdIEMmo (ORCPT ); Tue, 5 Sep 2017 08:42:44 -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 50972165C; Tue, 5 Sep 2017 05:42:44 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 624513F3E1; Tue, 5 Sep 2017 05:42:35 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 14/20] cifs: move to generic async completion Date: Tue, 5 Sep 2017 15:38:53 +0300 Message-Id: <1504615144-29770-15-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org cifs starts an async. crypto op and waits for their completion. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef Acked-by: Pavel Shilovsky --- fs/cifs/smb2ops.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) -- 2.1.4 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index fb2934b..982b39d 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2066,22 +2066,6 @@ init_sg(struct smb_rqst *rqst, u8 *sign) return sg; } -struct cifs_crypt_result { - int err; - struct completion completion; -}; - -static void cifs_crypt_complete(struct crypto_async_request *req, int err) -{ - struct cifs_crypt_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - static int smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) { @@ -2122,12 +2106,10 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) struct aead_request *req; char *iv; unsigned int iv_len; - struct cifs_crypt_result result = {0, }; + DECLARE_CRYPTO_WAIT(wait); struct crypto_aead *tfm; unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); - init_completion(&result.completion); - rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); if (rc) { cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__, @@ -2187,14 +2169,10 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) aead_request_set_ad(req, assoc_data_len); aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - cifs_crypt_complete, &result); + crypto_req_done, &wait); - rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); - - if (rc == -EINPROGRESS || rc == -EBUSY) { - wait_for_completion(&result.completion); - rc = result.err; - } + rc = crypto_wait_req(enc ? crypto_aead_encrypt(req) + : crypto_aead_decrypt(req), &wait); if (!rc && enc) memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); From patchwork Tue Sep 5 12:38:55 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: 111683 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2786053qge; Tue, 5 Sep 2017 05:43:22 -0700 (PDT) X-Google-Smtp-Source: ADKCNb73nN4Z1Up+LD8AF3ueRiWGgHOQ576+VaAWLZOH+eZfzCYhWB/X8D34Z5KvMUftugrCAOQT X-Received: by 10.99.110.141 with SMTP id j135mr4027131pgc.242.1504615402799; Tue, 05 Sep 2017 05:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615402; cv=none; d=google.com; s=arc-20160816; b=hNJSaWXTlDLf18GT65rpLtpgzK9j1nvXkCMOwJxuqN/y0/jbirps+H6tdrMVIIs42s IjTCmgQLBdCQAAamnRjK4mLou+yAOOJPARUzZZ0rivJspDlw/9ahSuC7q0WJRNOMpeZT s5hHf8P1McfTfiUrnAKqWCXSqBnvbcrIyXj1DOhlqWE4NqH1YTi+JgpVDkY85QxCjMfg pdpzmvag2uPouRDNQ8QAPVpKTCtTwTZBOYdgMKn8sDin4o1/At2xXz5Tj2uxgxuCFvrD OyamXv59ovnGwGQJ8OnJDRKnYeBNs3fOp2OAJkNogA0Xneio0iliiWogTclqNd5c9E35 NXFg== 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=0RUnoHp6WQYzsATta3isS5zOcHa1zha6MhJGmNoi/RY=; b=Yqm3QrTB1rDZ/c1Es3af3qVaDhy1nGJlbbovG+L5waT4uBho+WVelU3Gi2lNKFp1JH P7v/zvcT0LGyfAD84OQk3h9XfX73YorBRypA5edus3CqBQxwXw/0nYxyYQNwHzI00mnF QuonXlVC7EhcXbmsu8jUR8Pc8ielFzVmsxyWRStJbXlacod+UsRkCOFJMioyyC9PRD8p jUj8CXb0yjpjnKVqQa4OzOwyCIA5Zgt/Jp19XTftrQM88JW9eb+fF/GHUeloNw0VyOBM AMx9RTxQXrFC9hP1QKF0wAhcTG6lG136smhYJ3ODRuPOF70QThZmWhZaiWoWAhaGonbP ccdg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s61si286408plb.744.2017.09.05.05.43.22; Tue, 05 Sep 2017 05:43:22 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752038AbdIEMnR (ORCPT + 1 other); Tue, 5 Sep 2017 08:43:17 -0400 Received: from foss.arm.com ([217.140.101.70]:39814 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbdIEMnN (ORCPT ); Tue, 5 Sep 2017 08:43:13 -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 D544E1688; Tue, 5 Sep 2017 05:43:12 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CCC563F3E1; Tue, 5 Sep 2017 05:43:02 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 16/20] crypto: tcrypt: move to generic async completion Date: Tue, 5 Sep 2017 15:38:55 +0300 Message-Id: <1504615144-29770-17-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org tcrypt starts several async crypto ops and waits for their completions. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- crypto/tcrypt.c | 84 +++++++++++++++++---------------------------------------- 1 file changed, 25 insertions(+), 59 deletions(-) -- 2.1.4 diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 0022a18..802aa81 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -79,34 +79,11 @@ static char *check[] = { NULL }; -struct tcrypt_result { - struct completion completion; - int err; -}; - -static void tcrypt_complete(struct crypto_async_request *req, int err) -{ - struct tcrypt_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - static inline int do_one_aead_op(struct aead_request *req, int ret) { - if (ret == -EINPROGRESS || ret == -EBUSY) { - struct tcrypt_result *tr = req->base.data; + struct crypto_wait *wait = req->base.data; - ret = wait_for_completion_interruptible(&tr->completion); - if (!ret) - ret = tr->err; - reinit_completion(&tr->completion); - } - - return ret; + return crypto_wait_req(ret, wait); } static int test_aead_jiffies(struct aead_request *req, int enc, @@ -248,7 +225,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, char *axbuf[XBUFSIZE]; unsigned int *b_size; unsigned int iv_len; - struct tcrypt_result result; + struct crypto_wait wait; iv = kzalloc(MAX_IVLEN, GFP_KERNEL); if (!iv) @@ -284,7 +261,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, goto out_notfm; } - init_completion(&result.completion); + crypto_init_wait(&wait); printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, get_driver_name(crypto_aead, tfm), e); @@ -296,7 +273,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, } aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &result); + crypto_req_done, &wait); i = 0; do { @@ -397,21 +374,16 @@ static void test_hash_sg_init(struct scatterlist *sg) static inline int do_one_ahash_op(struct ahash_request *req, int ret) { - if (ret == -EINPROGRESS || ret == -EBUSY) { - struct tcrypt_result *tr = req->base.data; + struct crypto_wait *wait = req->base.data; - wait_for_completion(&tr->completion); - reinit_completion(&tr->completion); - ret = tr->err; - } - return ret; + return crypto_wait_req(ret, wait); } struct test_mb_ahash_data { struct scatterlist sg[TVMEMSIZE]; char result[64]; struct ahash_request *req; - struct tcrypt_result tresult; + struct crypto_wait wait; char *xbuf[XBUFSIZE]; }; @@ -440,7 +412,7 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec, if (testmgr_alloc_buf(data[i].xbuf)) goto out; - init_completion(&data[i].tresult.completion); + crypto_init_wait(&data[i].wait); data[i].req = ahash_request_alloc(tfm, GFP_KERNEL); if (!data[i].req) { @@ -449,8 +421,8 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec, goto out; } - ahash_request_set_callback(data[i].req, 0, - tcrypt_complete, &data[i].tresult); + ahash_request_set_callback(data[i].req, 0, crypto_req_done, + &data[i].wait); test_hash_sg_init(data[i].sg); } @@ -492,16 +464,16 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec, if (ret) break; - complete(&data[k].tresult.completion); - data[k].tresult.err = 0; + crypto_req_done(&data[k].req->base, 0); } for (j = 0; j < k; j++) { - struct tcrypt_result *tr = &data[j].tresult; + struct crypto_wait *wait = &data[j].wait; + int wait_ret; - wait_for_completion(&tr->completion); - if (tr->err) - ret = tr->err; + wait_ret = crypto_wait_req(-EINPROGRESS, wait); + if (wait_ret) + ret = wait_ret; } end = get_cycles(); @@ -679,7 +651,7 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs, struct hash_speed *speed, unsigned mask) { struct scatterlist sg[TVMEMSIZE]; - struct tcrypt_result tresult; + struct crypto_wait wait; struct ahash_request *req; struct crypto_ahash *tfm; char *output; @@ -708,9 +680,9 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs, goto out; } - init_completion(&tresult.completion); + crypto_init_wait(&wait); ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &tresult); + crypto_req_done, &wait); output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); if (!output) @@ -765,15 +737,9 @@ static void test_hash_speed(const char *algo, unsigned int secs, static inline int do_one_acipher_op(struct skcipher_request *req, int ret) { - if (ret == -EINPROGRESS || ret == -EBUSY) { - struct tcrypt_result *tr = req->base.data; - - wait_for_completion(&tr->completion); - reinit_completion(&tr->completion); - ret = tr->err; - } + struct crypto_wait *wait = req->base.data; - return ret; + return crypto_wait_req(ret, wait); } static int test_acipher_jiffies(struct skcipher_request *req, int enc, @@ -853,7 +819,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, unsigned int tcount, u8 *keysize, bool async) { unsigned int ret, i, j, k, iv_len; - struct tcrypt_result tresult; + struct crypto_wait wait; const char *key; char iv[128]; struct skcipher_request *req; @@ -866,7 +832,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, else e = "decryption"; - init_completion(&tresult.completion); + crypto_init_wait(&wait); tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC); @@ -887,7 +853,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - tcrypt_complete, &tresult); + crypto_req_done, &wait); i = 0; do { From patchwork Tue Sep 5 12:38:56 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: 111684 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2786282qge; Tue, 5 Sep 2017 05:43:35 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5WpM7spPKjjisL/zxP1qDe4JsC4eb3DhMeUJiEfc3wSSP7GdGZQAKnpJIIeAhu/C/PXaYD X-Received: by 10.84.131.100 with SMTP id 91mr4173742pld.247.1504615415737; Tue, 05 Sep 2017 05:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615415; cv=none; d=google.com; s=arc-20160816; b=z/BVCv+Piko8bvnjx0DC18/szJjHu+Tg4AbiCQLO+BfSozWdRkz75qbtOE4N1s6gQ+ boCghRbflCYcWjsVey/JN6biTmUuI10U7HG0F57i3wKT4PZJVEZy0RcpD2ioTnQIJWdZ 3EM7Ckr5QkYpj1pHN9AZxcHGeE/FAOv/UBCt5DNlglNdKmyQglNGUILljzsqzwz9ADUD 4aV6ddPgNO/SKIMQuEpkGDTDNoZnvQ5MIM3Ul1c3fee9dlCL9pIDtuWL9+f0EKIQf6kY My2SdiYkT5VW9f8yXIdTlm+MViLgFOg2E4fvqMnGWAcjAbZBxka5BsWgQyqFX3M8hOFw 8/Fw== 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=j0NbDfkd4meCZQWpDXufl1Y1pw2jCvvo6+pNCMAZIZM=; b=bCcHoogjeEATYObfESnrz1iO4anMR4g7FARGt6bNGqEge1lDBxWYD8DFiTfSYHihx/ E1ayOVpaMcJZV5AZfehbsRzpDLbsPOTDlAfOrjrw/ONojsus6137XNFIVNp+NJdjomF9 kGDCTotyrF7LVsPWxIseZeuMIdZ7nW39hHMhR7k7lyq1KGD2wnmJ0kfobuRha6gj2bAn x1Rtt/ypQlHBWwrMEipnae5N7NL4JnuNT7pKRYPoLKBXLIWjZim6gNhGNa/iE7bAsSXt b9RmPm+VGAxcWl1WxUR6EsGQd25bA6vEM3tdTSSUEZoup1w47OLK4FhYokjwv0pNyTRM lORA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m13si244475pfh.377.2017.09.05.05.43.35; Tue, 05 Sep 2017 05:43:35 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750731AbdIEMnd (ORCPT + 1 other); Tue, 5 Sep 2017 08:43:33 -0400 Received: from foss.arm.com ([217.140.101.70]:39866 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752182AbdIEMna (ORCPT ); Tue, 5 Sep 2017 08:43:30 -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 52B27165D; Tue, 5 Sep 2017 05:43:29 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 97D1F3F3E1; Tue, 5 Sep 2017 05:43:17 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 17/20] crypto: talitos: move to generic async completion Date: Tue, 5 Sep 2017 15:38:56 +0300 Message-Id: <1504615144-29770-18-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The talitos driver starts several async crypto ops and waits for their completions. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/talitos.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) -- 2.1.4 diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 79791c6..194a307 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -2037,22 +2037,6 @@ static int ahash_import(struct ahash_request *areq, const void *in) return 0; } -struct keyhash_result { - struct completion completion; - int err; -}; - -static void keyhash_complete(struct crypto_async_request *req, int err) -{ - struct keyhash_result *res = req->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen, u8 *hash) { @@ -2060,10 +2044,10 @@ static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen, struct scatterlist sg[1]; struct ahash_request *req; - struct keyhash_result hresult; + struct crypto_wait wait; int ret; - init_completion(&hresult.completion); + crypto_init_wait(&wait); req = ahash_request_alloc(tfm, GFP_KERNEL); if (!req) @@ -2072,25 +2056,13 @@ static int keyhash(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen, /* Keep tfm keylen == 0 during hash of the long key */ ctx->keylen = 0; ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - keyhash_complete, &hresult); + crypto_req_done, &wait); sg_init_one(&sg[0], key, keylen); ahash_request_set_crypt(req, sg, hash, keylen); - ret = crypto_ahash_digest(req); - switch (ret) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - ret = wait_for_completion_interruptible( - &hresult.completion); - if (!ret) - ret = hresult.err; - break; - default: - break; - } + ret = crypto_wait_req(crypto_ahash_digest(req), &wait); + ahash_request_free(req); return ret; From patchwork Tue Sep 5 12:38:57 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: 111685 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2786534qge; Tue, 5 Sep 2017 05:43:50 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5ro6ec/rogVi/Gi3hUJZH7kI5yopnTveggv8oBMizIZzrn5/x7uI973JZBfDQAaiKuKJCr X-Received: by 10.98.103.89 with SMTP id b86mr3480962pfc.319.1504615430787; Tue, 05 Sep 2017 05:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615430; cv=none; d=google.com; s=arc-20160816; b=vXqN00kCWhxWbvcYyU6EuQtXCU8J5wkrYucFDzCDXS7sh+By0ny361W15dQYOga5g3 EiK0m1y6EUhHFinReIMHW5dReBLCC87sY5v5H1fT7jkxhayF0MfiYG0zUlf+jYE/sL9y vIkAKaY3L4LEGqQsfe5t7kwxuG0yq8XH7+D4DFFJrYvC2mo0DuvyUMWYtzVPyKpSZpUC 2MfcmlaLBevAVZtMoZfd6RySqVd56waxO9Y7zdov5GZgAiT6F/pCOnt+oFNB3N7YLNBz 0lXPziiEI8iaT/xX7ZaxKSjY5OZ1AS73/rEifoHmqfduaUHvdV3w9r1WhJ62hypr6/zd /sjA== 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=ZEEwY7S0lvfkzX5eSnqpbx2gek6uifwcDnkIXVl4mV0=; b=ZfaxJzDu4ECIJe1wfb7wkrxOIah9SAYClP2FGBh5EKOrGK8euqH86nYtDcqDXeM2Zw UZLhFGz3Pw8Om5T4yc7g+0GIaTH+tTv1rjXAxXn2mQtqHNC1DHc/W+bwGwgFOSm3FDwb XFrN9YHt7vtgt9jyKXNgpAyvwDRXedcCILAVcwxKk/FpCCxa7uRagVBSu8LpC2QnRqA5 MiXm9Ldo3NcaBcl1be9skTdgSTySwIlfi5Mfk4UQd0/UFZgR+EB06BdpJhct8+zRb5kR +oS3l4pGaAR+6e5/6phv/Dyibey0i7ATC9cQtlIISoZzFtkRGzZIa1F3E2R883W2tSi6 OXzw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c30si196431pgn.746.2017.09.05.05.43.50; Tue, 05 Sep 2017 05:43:50 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752284AbdIEMns (ORCPT + 1 other); Tue, 5 Sep 2017 08:43:48 -0400 Received: from foss.arm.com ([217.140.101.70]:39922 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752282AbdIEMno (ORCPT ); Tue, 5 Sep 2017 08:43:44 -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 5E836168F; Tue, 5 Sep 2017 05:43:43 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 35A013F3E1; Tue, 5 Sep 2017 05:43:33 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 18/20] crypto: qce: move to generic async completion Date: Tue, 5 Sep 2017 15:38:57 +0300 Message-Id: <1504615144-29770-19-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The qce driver starts several async crypto ops and waits for their completions. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/qce/sha.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) -- 2.1.4 diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index 47e114a..53227d7 100644 --- a/drivers/crypto/qce/sha.c +++ b/drivers/crypto/qce/sha.c @@ -349,28 +349,12 @@ static int qce_ahash_digest(struct ahash_request *req) return qce->async_req_enqueue(tmpl->qce, &req->base); } -struct qce_ahash_result { - struct completion completion; - int error; -}; - -static void qce_digest_complete(struct crypto_async_request *req, int error) -{ - struct qce_ahash_result *result = req->data; - - if (error == -EINPROGRESS) - return; - - result->error = error; - complete(&result->completion); -} - static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key, unsigned int keylen) { unsigned int digestsize = crypto_ahash_digestsize(tfm); struct qce_sha_ctx *ctx = crypto_tfm_ctx(&tfm->base); - struct qce_ahash_result result; + struct crypto_wait wait; struct ahash_request *req; struct scatterlist sg; unsigned int blocksize; @@ -405,9 +389,9 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key, goto err_free_ahash; } - init_completion(&result.completion); + crypto_init_wait(&wait); ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - qce_digest_complete, &result); + crypto_req_done, &wait); crypto_ahash_clear_flags(ahash_tfm, ~0); buf = kzalloc(keylen + QCE_MAX_ALIGN_SIZE, GFP_KERNEL); @@ -420,13 +404,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key, sg_init_one(&sg, buf, keylen); ahash_request_set_crypt(req, &sg, ctx->authkey, keylen); - ret = crypto_ahash_digest(req); - if (ret == -EINPROGRESS || ret == -EBUSY) { - ret = wait_for_completion_interruptible(&result.completion); - if (!ret) - ret = result.error; - } - + ret = crypto_wait_req(crypto_ahash_digest(req), &wait); if (ret) crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); From patchwork Tue Sep 5 12:38:58 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: 111686 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2786780qge; Tue, 5 Sep 2017 05:44:05 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4sXFoh0bI4Q9qqbX6Eyi4MslCkwLwCaMNKF5wBoTJLr0fz+r/X/8Sx97BVoVrvg2lOYsCt X-Received: by 10.99.99.197 with SMTP id x188mr3875859pgb.49.1504615444880; Tue, 05 Sep 2017 05:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504615444; cv=none; d=google.com; s=arc-20160816; b=cVti+5hSsnlaFpZbHGdQZNX0bvT3dsVnMfUg7Yv8PqLFH65+7yHOzA+Cbd8Zqd9pQ4 gr6pWTwvy4L1ryhs8+P1jCyENsGMXS6T4PeVc9CUs7A68wV+Ja/sfkPR3AhWPfOJPtEZ 8PdD5K9DRGXunY/vThGlb5gTVZydCOurV1zx1FcQY3hh1hGIrtKtf4PA7AXSQjh2HWcE RBIdG8BPjNXhtqsQtCph4NWgSgWcIi5Rc5lSKHnNOPAbf1kauh1z4qYOpjcY5MAR2UVG w3m6BjYKHoR+1lWLyme9Tx6KiJa+WIyfjkCZjPatsLQvqMPQN8g0ph80QrocAlF7b0Hw LIug== 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=A7zELhOaEjZb/+lrLAbPp1vdePqcxK/3gRtFdVYfz7A=; b=JWTkbtF2iU/8CkaL42jx5a3ElReG7g9sz45sk77LvxHdasMm5SOeD8PSD/18L2tCh3 oZW4tx8tWRYh4UM8Jmyrt+zGvfND9RENX+FaZBP3ARVfc3c4qePD75okpnaFH4RYWBGY nc8+BCJ1n+t4DmflPEwlrwUw9+4weEJ01fx1C0yCzZc+F9MLIPPZCUSCEwiqim9xBHTS wa+KgDu5/Unk2YwWpb63RN3eEx46SvIt/bFurCW/lx2gVJbLxVN+DulSm1FqvBg1hUgD 04Le/TYG1vx5uwxKSZuUqDDZStck17zmoaf6FAmb386kCFeYn7sVlS//F8XGLBkL07I8 9vRQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12si305855plk.324.2017.09.05.05.44.04; Tue, 05 Sep 2017 05:44:04 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752333AbdIEMoD (ORCPT + 1 other); Tue, 5 Sep 2017 08:44:03 -0400 Received: from foss.arm.com ([217.140.101.70]:39976 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbdIEMn7 (ORCPT ); Tue, 5 Sep 2017 08:43: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 795D2165C; Tue, 5 Sep 2017 05:43:58 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 406FF3F3E1; Tue, 5 Sep 2017 05:43:48 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, netdev@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang Subject: [PATCH v8 19/20] crypto: mediatek: move to generic async completion Date: Tue, 5 Sep 2017 15:38:58 +0300 Message-Id: <1504615144-29770-20-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504615144-29770-1-git-send-email-gilad@benyossef.com> References: <1504615144-29770-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The mediatek driver starts several async crypto ops and waits for their completions. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef Acked-by: Ryder Lee --- drivers/crypto/mediatek/mtk-aes.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) -- 2.1.4 diff --git a/drivers/crypto/mediatek/mtk-aes.c b/drivers/crypto/mediatek/mtk-aes.c index 9e845e8..e2c7c95 100644 --- a/drivers/crypto/mediatek/mtk-aes.c +++ b/drivers/crypto/mediatek/mtk-aes.c @@ -137,11 +137,6 @@ struct mtk_aes_gcm_ctx { struct crypto_skcipher *ctr; }; -struct mtk_aes_gcm_setkey_result { - int err; - struct completion completion; -}; - struct mtk_aes_drv { struct list_head dev_list; /* Device list lock */ @@ -936,17 +931,6 @@ static int mtk_aes_gcm_crypt(struct aead_request *req, u64 mode) &req->base); } -static void mtk_gcm_setkey_done(struct crypto_async_request *req, int err) -{ - struct mtk_aes_gcm_setkey_result *result = req->data; - - if (err == -EINPROGRESS) - return; - - result->err = err; - complete(&result->completion); -} - /* * Because of the hardware limitation, we need to pre-calculate key(H) * for the GHASH operation. The result of the encryption operation @@ -962,7 +946,7 @@ static int mtk_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key, u32 hash[4]; u8 iv[8]; - struct mtk_aes_gcm_setkey_result result; + struct crypto_wait wait; struct scatterlist sg[1]; struct skcipher_request req; @@ -1002,22 +986,17 @@ static int mtk_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key, if (!data) return -ENOMEM; - init_completion(&data->result.completion); + crypto_init_wait(&data->wait); sg_init_one(data->sg, &data->hash, AES_BLOCK_SIZE); skcipher_request_set_tfm(&data->req, ctr); skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG, - mtk_gcm_setkey_done, &data->result); + crypto_req_done, &data->wait); skcipher_request_set_crypt(&data->req, data->sg, data->sg, AES_BLOCK_SIZE, data->iv); - err = crypto_skcipher_encrypt(&data->req); - if (err == -EINPROGRESS || err == -EBUSY) { - err = wait_for_completion_interruptible( - &data->result.completion); - if (!err) - err = data->result.err; - } + err = crypto_wait_req(crypto_skcipher_encrypt(&data->req), + &data->wait); if (err) goto out;