From patchwork Wed Oct 18 07:00:33 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: 116212 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5743047qgn; Wed, 18 Oct 2017 00:02:21 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA9UihwSs3f9lCw+KE9BnCWDWxixgw95nknBN1lTf/XkLlriBCYFX/Z1BaI0PLaQpXzxfvn X-Received: by 10.101.72.65 with SMTP id i1mr12957837pgs.436.1508310141710; Wed, 18 Oct 2017 00:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310141; cv=none; d=google.com; s=arc-20160816; b=cChsXlXjZkG6aMnCNtq0rEJXDeTJIv/w1vq/KOEOMYqT2TeCuafZzJZcQtQjqC0alv 7KV+AfIzXoc0CkMAupf205ceymsn0gRuiG2n1KppucRIrecPuJsP0putmupUGRPT6n1z MtYkyIBNPyQvlCK/5P/wHyyMKpD2ELusOQ+e432cBQuaTf6aOR4ocDWBmTBXi/iZrn/A /Z290f5VyDeK6bO0jYchlreqIduj4OD+/oHbf5QO5QyVJ05Ul8vT4/ncL19nHvuuaDXx K9IGofgY37iYwyFfzhDnzXjxYFN8pyV47rbQ6Gh/vxC4PUL2c3dXZ4sXmkWhoegxYWbY iPzg== 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=zg4B5KCNiqTWEe9vpfrw9jHFAvmRd4XOZLcLphDf5M0=; b=ptiBpWA39ONPh1KbL91xhzgm0fMv5+uImbueHUCDb3z/2v39YJxIDrhfLjfx6xEWBX 3pVC4nnFsyd5pS78DkETwSR3UJsKt+y60ah6s7IRzPgGgcaTxUz+FS95YJkw1NDGBx2r c7emyip5RASyBLnRM1eA08H2RcU/bMiEYL4hTjPSqM+ffF/ns+ZxS/hOBesfGKu8eE6F ZclbO1IljhgQQ+qdWDSC1fcqAqyqh9P81haY4lrhr1KoL9sfoOlyRnaQTuXnu2pxpaTU HafKVkhR8VIJM6f3DuAQt8NMydO96nYoqw/PV1nkRz2EzSArmer46wXVT2Q8xaoLkD/Y uTgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si994714plt.587.2017.10.18.00.02.21; Wed, 18 Oct 2017 00:02:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935517AbdJRHCU (ORCPT + 27 others); Wed, 18 Oct 2017 03:02:20 -0400 Received: from foss.arm.com ([217.140.101.70]:33248 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932290AbdJRHCP (ORCPT ); Wed, 18 Oct 2017 03:02:15 -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 2F9C71529; Wed, 18 Oct 2017 00:02:15 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 169CF3F590; Wed, 18 Oct 2017 00:02: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 01/20] crypto: change transient busy return code to -ENOSPC Date: Wed, 18 Oct 2017 08:00:33 +0100 Message-Id: <1508310057-25369-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -ENOSPC. Signed-off-by: Gilad Ben-Yossef --- crypto/algapi.c | 6 ++++-- crypto/cryptd.c | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/crypto/algapi.c b/crypto/algapi.c index aa699ff..60d7366 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 = -ENOSPC; goto out; + } + err = -EBUSY; if (queue->backlog == &queue->list) queue->backlog = &request->list; } diff --git a/crypto/cryptd.c b/crypto/cryptd.c index 0508c48..bd43cf5 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 == -ENOSPC) goto out_put_cpu; queue_work_on(cpu, kcrypto_wq, &cpu_queue->work); From patchwork Wed Oct 18 07:00:34 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: 116213 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5743298qgn; Wed, 18 Oct 2017 00:02:38 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCSgQWBuMInjKh6IHBPu7l8mp4qND39xUAYxCNIG6W9eLvS/odMjzvUrS8vsyM72KK6xEsk X-Received: by 10.84.240.70 with SMTP id h6mr14201853plt.109.1508310158111; Wed, 18 Oct 2017 00:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310158; cv=none; d=google.com; s=arc-20160816; b=DhsF8UA3QP3S6cuAAJ2Uk2JtTW2ZPjNkMjhMLavHioyMjU8CxuNCu6Y5fVR1TFz2Fx Km+0ac31Pf29+yI72PSwB3ET9CQJuwwXPvsw40UDmVoQIglV53hGXVOQj0v2Pdl6OAJL 4Cjbzuqh+bJvoClUDyg8sCWHgU3kz0pmwUJwaxxlqi0n15oLXCXIC7d4Us6532aJK7/b fpYKgV3K2h8CIh267L/eS1cabn03WMdZqDs/K6ChLmpJWYBE/+LqWfWYV4hE8P9ZywPG B/MeOZnbubzTuGEFIke6GXvZVI1niGtlOdBA6RymuWOodGDVpf3QJnf5xnn1sYcUYbiX wYZQ== 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=z4l4zwvH0TjGCQVfT11MC7MncPts0ezZFmCFlus0l2w=; b=e/iNFrrxHO6DQ36oCirMvRjSKIahtsNL+NOWlzyFrQtyvLW5snG203Z7teLfuxJljT cRlvC07SUcc1M9SCw82cWZoVZkGKR2MZs/vjlD2swrsUFxFh13VHA9QdRPK4YwtKvfRF uyDsdS+R52YApuzjFeVJzLpmJYF32e1EJJ9+A6rtjXNBKiwaQGhxRp7ydKjfWeOHi2XZ rXCptRDma+4jNS56O6MkdINEMYzVdyBH6h9Gb2H6bmLGxAwTXkqlTUXnfnhaiA+jUiwW Ka7AeKjC154KlxIWdr4NQ+fwiDVkKz7GCPCgKvTBHA+dT6RJtUEF4mfJ4x1iaDlAdyjF tTgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f19si7328514plr.246.2017.10.18.00.02.37; Wed, 18 Oct 2017 00:02:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966494AbdJRHCg (ORCPT + 27 others); Wed, 18 Oct 2017 03:02:36 -0400 Received: from foss.arm.com ([217.140.101.70]:33294 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932290AbdJRHCa (ORCPT ); Wed, 18 Oct 2017 03:02: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 8A68D15BE; Wed, 18 Oct 2017 00:02:29 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 33F363F590; Wed, 18 Oct 2017 00:02: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 02/20] crypto: ccp: use -ENOSPC for transient busy indication Date: Wed, 18 Oct 2017 08:00:34 +0100 Message-Id: <1508310057-25369-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace -EBUSY with -ENOSPC 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.7.4 diff --git a/drivers/crypto/ccp/ccp-crypto-main.c b/drivers/crypto/ccp/ccp-crypto-main.c index 35a9de7..b95d199 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 = -ENOSPC; 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..1b5035d 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 = -ENOSPC; + } } else { ret = -EINPROGRESS; ccp->cmd_count++; From patchwork Wed Oct 18 07:00:35 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: 116214 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5743471qgn; Wed, 18 Oct 2017 00:02:50 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCXPzR3dRATSMUKVKuh+klCpuw9VGMtpAPj8cjWWZDZy73YsPjBs/ugFjU1WuaADLTei61B X-Received: by 10.101.81.198 with SMTP id i6mr12833571pgq.451.1508310170004; Wed, 18 Oct 2017 00:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310169; cv=none; d=google.com; s=arc-20160816; b=x4K6E0L1DfqmALDIEdW5Cp8PusN2iXXZvCo+LDOAUlXUMJjcUPkajq5eoJr+vjog4C djq1ZaKtjkklLs/wmuZeY1xaTDKf0u1Rj8tgthuTf5+V8tpRk24t4yfWTAAjTP7cL6yg 8fbbY8VwYxH2iHSW+3j3m71sf2zsOdJDLXVzhB0NkCZAPM9O9SwOllvzEBsQOWOdqzWk CI2l/fw5VSqBP5G5NHAEZvrCSUX5dYGt2XV1mqA1F840hxey8a9y0TzvcaNCS7a8Pgep ZwdGrsCHNkHPfVqn8BFqHm8ppU9JimrBgB6UlLb3oMJRAgsQMI6Q1qC2y2HygeYsc94I 3T1A== 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=BIWQ2O8mY4CeK17p+aXfGTb8oWz17VDMK4hPtcHK/SM=; b=LWLOmjoV0kFWZOVo1MdzSa1uxEOMinUsZ//rQh2aqET/+121uwhAF2ijwNN8tAlivX bKEPWwad3T/xPgLsT+/6AwRtXY6wDNkgJbpZilaOO8J9+XZQaidLlVI6qyVeukrNv6z8 pFpSW3PBymsy3aUQ6/T+1sThfrTgkQBGaPeAcysImMYyhjNV7NAYUcyN5T0iAzZP1LRb uvvaBljqKG6Wd98L0b8SjUgml0VM4XaeK4x3+X7YJlK8iEYD2DKx8rjDm3E7C4er8ZHm 4x6Pht5w4ecP0SPhITa9M+aNRiYoBL1aERVmmPyo1mIYiZUMMQAsnD89EQaYdgyBt+gi zl5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b61si5969307plb.488.2017.10.18.00.02.49; Wed, 18 Oct 2017 00:02:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966521AbdJRHCr (ORCPT + 27 others); Wed, 18 Oct 2017 03:02:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33336 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966495AbdJRHCn (ORCPT ); Wed, 18 Oct 2017 03:02:43 -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 73DA4F; Wed, 18 Oct 2017 00:02:43 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 22BFA3F590; Wed, 18 Oct 2017 00:02:34 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 03/20] net: use -ENOSPC for transient busy indication Date: Wed, 18 Oct 2017 08:00:35 +0100 Message-Id: <1508310057-25369-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace -EBUSY with -ENOSPC 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.7.4 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c index 37db44f..4dd95cd 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 == -ENOSPC) err = NET_XMIT_DROP; goto out_free; } diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index b00e4a4..d57aa64 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 -ENOSPC: err = NET_XMIT_DROP; break; diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c index 7802b72..3bd9d80 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 == -ENOSPC) err = NET_XMIT_DROP; goto out_free; } diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 89910e2..c04d995 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 -ENOSPC: err = NET_XMIT_DROP; break; From patchwork Wed Oct 18 07:00:37 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: 116215 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5743892qgn; Wed, 18 Oct 2017 00:03:18 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBYomCx1vQZ9tBqRKOsyRLvunZ+Y/9OosCGHF2cajxMYZ+PYBIM0/Dn1CwClmxpW+l2ESsk X-Received: by 10.99.98.197 with SMTP id w188mr12951862pgb.41.1508310198250; Wed, 18 Oct 2017 00:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310198; cv=none; d=google.com; s=arc-20160816; b=a0uZ+oOgKIMJRZepId6JmvxoBf1LM/KxZqzC4VHWnCQ7UWqyce1Jx3dXfezUkGNCa9 Ha8jcyjQeZxZtL63hSUwLUh/bcJx65thzWShAOMguyat5VGW/eVo+vRzpF4utp64AGmZ J0Bwvml9YIlk0YIm/n+Mtkw5lxL+odEXevcbSWlz/lqcdt96iOE2tMrG2f9wxHlGhh84 ZKWGnPtwpjMhNB6p//ofmFk6A4MYrNgPdK9sGgmpMCngEFrU/qD7sMtWXMYzHcUN2oI8 lv46oa92Bnbu0NM55IExE2Lpwf3gEsB9UvhM8uaYMChvyfX1zfTlpuuJSQN3mXh5vNH8 Ft7A== 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=LFdLIGhk89Nk3xz3nzAcr4UBIYZLnnWiktWdiwd9iDw=; b=YbRXli2Pqs6kfPNJ49DtwUHgSZ3UQ/9Kkcx7wJWESfetzny4ZNLqsvkEDZk5Be5yt7 OoX2jlIK/DPxsqcp05LQZbwnERLgfC0yJC1nITsp/hF/0TXuVHyS8JcIpgOWCGa5ANAk EgwnLMTBPYjyjU5mVVwdzHYj9TVNaDRvU/ECSwF5qI+0rizvpM3q5/xAla7iGdMs6VMc UYQbpk0nz56oP2A5Uo8Oj5x/cRNp4iIgC47qTs4tTXt5KaWm6XKG2nREzifxyfAb1LGS hV6hKJlnD2RJTUtyuMhCqBrmQK93plbfM2788sJVywofG139X4dKRpRrvplFCA0eeFSt YSPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si6534110pgn.524.2017.10.18.00.03.17; Wed, 18 Oct 2017 00:03:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966554AbdJRHDP (ORCPT + 27 others); Wed, 18 Oct 2017 03:03:15 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33446 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966495AbdJRHDL (ORCPT ); Wed, 18 Oct 2017 03:03:11 -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 EA513F; Wed, 18 Oct 2017 00:03:10 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 96C273F590; Wed, 18 Oct 2017 00:03: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 05/20] crypto: marvell/cesa: remove redundant backlog checks on EBUSY Date: Wed, 18 Oct 2017 08:00:37 +0100 Message-Id: <1508310057-25369-6-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.4 diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c index b657e7c..ff73aa5 100644 --- a/drivers/crypto/marvell/cesa.c +++ b/drivers/crypto/marvell/cesa.c @@ -181,8 +181,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 Wed Oct 18 07:00:38 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: 116216 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5744063qgn; Wed, 18 Oct 2017 00:03:31 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDVz32ZmZuHgTEuOPxHRWzghKAMpEY02pLi8VSxEbe2/zxaQLMoFgQqZamR1IHuNj6RVrKS X-Received: by 10.98.35.18 with SMTP id j18mr14048924pfj.37.1508310211753; Wed, 18 Oct 2017 00:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310211; cv=none; d=google.com; s=arc-20160816; b=lKax6EmAyBrs9tdYINeihXr7NCSnQScrTNLKY5ZQ7X5kryzi1VF1jmoV9aIJm2sH/Y MGQG5hGyoO8IVkr04AHYgkSc5kaDjNGg4425bV7+BkSWtt/kyNaIv0R4Mln7xKvHkMz5 4ABhfezuNc8WVxPrPQOIqN98Oaic+fmiZbS2bgyYPlBd8EMQPZG32Bm+yJLdJn2S1EeG PZHI8z6Id4fJCQOxj6C27ov1GPU+rUl8qyHlDGMXlc8TNdbNKaSYbrAtvpdpJNZQIyTp zddGvygvWis0aZSZr8bsU27Ij6y1uCCowTW/lBa5ko7bgsGd6wvO33O5r5EOyodQIAeq lrwA== 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=1ArdGSKo8zFcbVU2ruVtqy3op3texlfgWkyUkCYAy2U=; b=SonCKfJkfxRer5M+UvcNd/F9/ua3WB4ZM7qZ37ZkTzELH3baBzTacJLoO2zxtWTJ9Y /YBjkx4V9Fmr4Em6dfOVayz3YRN7LIPZ2WYVsQdvyNvT6TT6cr7moDMx171cNpkPOxPe cAMlcJGxWA8qhJXXIjUd+L/IBgSmzJNQiAG+ju1qqazdaltDQDV/uoVGbDbYt4TTj0UW hKvpck+ldnldWHayPjkSjOV2Br9AujaVmmkuxkfSAX0P8kBAzXoR2hlGdjVEUwpeLjt3 0r/45OsAh06AAArLONq73LT7lSHdm73fRrHZFEgDPOkgcA2JXTQ4p04gNYpiSfBn+3gO boeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si6534110pgn.524.2017.10.18.00.03.31; Wed, 18 Oct 2017 00:03:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966577AbdJRHDa (ORCPT + 27 others); Wed, 18 Oct 2017 03:03:30 -0400 Received: from foss.arm.com ([217.140.101.70]:33524 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756802AbdJRHD0 (ORCPT ); Wed, 18 Oct 2017 03:03:26 -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 7F2D815BE; Wed, 18 Oct 2017 00:03:25 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B39A83F590; Wed, 18 Oct 2017 00:03:16 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , Eric Biggers , Jonathan Cameron , 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-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 Subject: [PATCH v10 06/20] crypto: introduce crypto wait for async op Date: Wed, 18 Oct 2017 08:00:38 +0100 Message-Id: <1508310057-25369-7-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.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 Wed Oct 18 07:00:39 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: 116217 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5744216qgn; Wed, 18 Oct 2017 00:03:46 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCSyT3dunEN21Q0OpESG3eLIcW+uKFJfbsxiiHtUEc40vQV19Q6PbSwjRlOCXtabWdykD78 X-Received: by 10.84.204.136 with SMTP id b8mr14163520ple.361.1508310226552; Wed, 18 Oct 2017 00:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310226; cv=none; d=google.com; s=arc-20160816; b=0HoDzRQm3m+J7FJjrBfsDUuIk2SVyJ6itwW/nvjnNE0Fv4pHEBt28xYwQe44arZvX6 LBepINZtu1CKBl7mmobufZ+UTXBoc2+djhagFf+7tG/NAfKkTsyWn074Ap4bd2SFU3Uz HCth0C/8rt/Oq17zePSW4VxPv+j5Teu0BWxC8a7VoAn3LYCK1WE2keHmnnyYh8Hs9M3o qhLYihnOB5uGBx9mM8H1P77qqKk9skmuc6HHorMm12XSuWsyszZbQB3oDse3p1x6jfs0 8Qv0hgnwyKgKaPIBfpVAyQdR6R29JLgiAIW9HT9n8isTtAd7JVbMmeTAn/2X59BNQ/qX O8KQ== 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=uKdEE0abP+czySevIBy+WUypfPZJgJVzXl/UZI5OypE=; b=fRyiDsFm00OsggB8sUrwP03xo8X2zEX+Ipb4xvo03yyWWl11rsSrqgld23z3L7syMY TiH9PhtgBHVsLruSpnfqWq3jN2xsALspm9DS/iKWhiPI8wzznse+JQ8v8Cg/eHmA3ZH6 jcOQAaqbqg2I9sZpfEftcKa1VDgZljS5Q3hEDLl89z1Be6m9GBrj3A1SYHLksMVYjawa YwJoN4Uf309+rGWwYNPD3+Tawdgm40UqTZieGANaiHgiCz72n05lvJuUAnnDXWDbQkK7 jemqALVO4ZtVoEQ0ayx5OEcadsDIu7P8gtd68u0JoP+cz7mZmG6UREATcfBzxyGewuNi 6VIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si6534110pgn.524.2017.10.18.00.03.46; Wed, 18 Oct 2017 00:03:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761302AbdJRHDp (ORCPT + 27 others); Wed, 18 Oct 2017 03:03:45 -0400 Received: from foss.arm.com ([217.140.101.70]:33566 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756802AbdJRHDk (ORCPT ); Wed, 18 Oct 2017 03:03:40 -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 0027BF; Wed, 18 Oct 2017 00:03:40 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABC893F590; Wed, 18 Oct 2017 00:03:31 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 07/20] crypto: move algif to generic async completion Date: Wed, 18 Oct 2017 08:00:39 +0100 Message-Id: <1508310057-25369-8-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org algif starts several async crypto ops and waits for their completion. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef --- crypto/af_alg.c | 27 --------------------------- crypto/algif_aead.c | 8 ++++---- crypto/algif_hash.c | 30 ++++++++++++++---------------- crypto/algif_skcipher.c | 9 ++++----- include/crypto/if_alg.h | 15 +-------------- 5 files changed, 23 insertions(+), 66 deletions(-) -- 2.7.4 diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 337cf38..85cea9d 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -481,33 +481,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) } EXPORT_SYMBOL_GPL(af_alg_cmsg_send); -int af_alg_wait_for_completion(int err, struct af_alg_completion *completion) -{ - switch (err) { - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&completion->completion); - reinit_completion(&completion->completion); - err = completion->err; - break; - }; - - return err; -} -EXPORT_SYMBOL_GPL(af_alg_wait_for_completion); - -void af_alg_complete(struct crypto_async_request *req, int err) -{ - struct af_alg_completion *completion = req->data; - - if (err == -EINPROGRESS) - return; - - completion->err = err; - complete(&completion->completion); -} -EXPORT_SYMBOL_GPL(af_alg_complete); - /** * af_alg_alloc_tsgl - allocate the TX SGL * diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index 516b38c..aacae08 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c @@ -278,11 +278,11 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg, /* Synchronous operation */ aead_request_set_callback(&areq->cra_u.aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG, - af_alg_complete, &ctx->completion); - err = af_alg_wait_for_completion(ctx->enc ? + crypto_req_done, &ctx->wait); + err = crypto_wait_req(ctx->enc ? crypto_aead_encrypt(&areq->cra_u.aead_req) : crypto_aead_decrypt(&areq->cra_u.aead_req), - &ctx->completion); + &ctx->wait); } /* AIO operation in progress */ @@ -554,7 +554,7 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk) ctx->merge = 0; ctx->enc = 0; ctx->aead_assoclen = 0; - af_alg_init_completion(&ctx->completion); + crypto_init_wait(&ctx->wait); ask->private = ctx; diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 5e92bd2..76d2e71 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -26,7 +26,7 @@ struct hash_ctx { u8 *result; - struct af_alg_completion completion; + struct crypto_wait wait; unsigned int len; bool more; @@ -88,8 +88,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, if ((msg->msg_flags & MSG_MORE)) hash_free_result(sk, ctx); - err = af_alg_wait_for_completion(crypto_ahash_init(&ctx->req), - &ctx->completion); + err = crypto_wait_req(crypto_ahash_init(&ctx->req), &ctx->wait); if (err) goto unlock; } @@ -110,8 +109,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len); - err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req), - &ctx->completion); + err = crypto_wait_req(crypto_ahash_update(&ctx->req), + &ctx->wait); af_alg_free_sg(&ctx->sgl); if (err) goto unlock; @@ -129,8 +128,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, goto unlock; ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); - err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), - &ctx->completion); + err = crypto_wait_req(crypto_ahash_final(&ctx->req), + &ctx->wait); } unlock: @@ -171,7 +170,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, } else { if (!ctx->more) { err = crypto_ahash_init(&ctx->req); - err = af_alg_wait_for_completion(err, &ctx->completion); + err = crypto_wait_req(err, &ctx->wait); if (err) goto unlock; } @@ -179,7 +178,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, err = crypto_ahash_update(&ctx->req); } - err = af_alg_wait_for_completion(err, &ctx->completion); + err = crypto_wait_req(err, &ctx->wait); if (err) goto unlock; @@ -215,17 +214,16 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); if (!result && !ctx->more) { - err = af_alg_wait_for_completion( - crypto_ahash_init(&ctx->req), - &ctx->completion); + err = crypto_wait_req(crypto_ahash_init(&ctx->req), + &ctx->wait); if (err) goto unlock; } if (!result || ctx->more) { ctx->more = 0; - err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), - &ctx->completion); + err = crypto_wait_req(crypto_ahash_final(&ctx->req), + &ctx->wait); if (err) goto unlock; } @@ -476,13 +474,13 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk) ctx->result = NULL; ctx->len = len; ctx->more = 0; - af_alg_init_completion(&ctx->completion); + crypto_init_wait(&ctx->wait); ask->private = ctx; ahash_request_set_tfm(&ctx->req, hash); ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG, - af_alg_complete, &ctx->completion); + crypto_req_done, &ctx->wait); sk->sk_destruct = hash_sock_destruct; diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 8ae4170..9954b07 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -129,12 +129,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, skcipher_request_set_callback(&areq->cra_u.skcipher_req, CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG, - af_alg_complete, - &ctx->completion); - err = af_alg_wait_for_completion(ctx->enc ? + crypto_req_done, &ctx->wait); + err = crypto_wait_req(ctx->enc ? crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) : crypto_skcipher_decrypt(&areq->cra_u.skcipher_req), - &ctx->completion); + &ctx->wait); } /* AIO operation in progress */ @@ -388,7 +387,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) ctx->more = 0; ctx->merge = 0; ctx->enc = 0; - af_alg_init_completion(&ctx->completion); + crypto_init_wait(&ctx->wait); ask->private = ctx; diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 75ec9c6..6abf0a3 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -40,11 +40,6 @@ struct alg_sock { void *private; }; -struct af_alg_completion { - struct completion completion; - int err; -}; - struct af_alg_control { struct af_alg_iv *iv; int op; @@ -152,7 +147,7 @@ struct af_alg_ctx { void *iv; size_t aead_assoclen; - struct af_alg_completion completion; + struct crypto_wait wait; size_t used; size_t rcvused; @@ -177,19 +172,11 @@ void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new); int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); -int af_alg_wait_for_completion(int err, struct af_alg_completion *completion); -void af_alg_complete(struct crypto_async_request *req, int err); - static inline struct alg_sock *alg_sk(struct sock *sk) { return (struct alg_sock *)sk; } -static inline void af_alg_init_completion(struct af_alg_completion *completion) -{ - init_completion(&completion->completion); -} - /** * Size of available buffer for sending data from user space to kernel. * From patchwork Wed Oct 18 07:00: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: 116219 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5744610qgn; Wed, 18 Oct 2017 00:04:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T2NYmhB3V2U4Q7oVKI0CbsyhwpgQMsBfB6fTez56Ie2+tCBQUf5d/bMnA550F0BNtCWy8X X-Received: by 10.84.246.130 with SMTP id m2mr6297904pll.16.1508310254447; Wed, 18 Oct 2017 00:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310254; cv=none; d=google.com; s=arc-20160816; b=WIyOz9ATUsQVxbTHHeErAEIm1bcDn2+DUKz0LbJ89wg79CXpL2r1qki2Mu4EEnvFWJ CkafjO/Tt3fVY+VDI9OChyIsK/TfL79PdaIREC/X20AAk7aTDc3f4fy66Vd/xa8yinWy 9ztcnaiP9HxB6bG4O8oOiRAAZn5srMxPjplL/EDjmMEBhAr6hNfbegWoZphejcmlD8AG ciyKwpBcU0xZgbF3mAziv+rvqkzZMU9oSa0Yw4rGGVVgj3RhvuVeovjOz4hFDsfEvjIu YnkqLHoEsfaFBpL5CIC7VM69Y+XEBieV9zz7QSS984PaVLqNrMJmGxSk3YxdEIfJrEFM tZOw== 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=jeAvlUTMhFWnlHMR/QVcJRSV+C6WT1XXKESVKErteeg=; b=j/H+ZAP/Qfm7xHeo2yk1gVnDjiOlZb+WJiUtfYVhJjZS33eYmZRKRlhLgNBxlYLrv7 TjonHd+5Vm4Xs6jEJzSRldDs1Y4nnAK0fMD/5KhfkHdMHvq+7xqLmyMoz33zPG/mpVY0 Fv7z7Hfr16/OoHk5NcQXskLnnV6fVxGb5lM13hAsjgU4341ndz+dSVEoS3373m/1gbf6 29hDz96W0BhUSzWfMNGzA+sHSqCn2TZk1hRPhVuZhaRpAyG1LfGUL5yHubncAl81uLVO k1tgClkxUIckNlM55owVKl1jyLeG2eRAdYlZQWhtdALIZLcMVCDKTCVW8zVDsKAVXuxC s/4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u13si6540664pgq.234.2017.10.18.00.04.14; Wed, 18 Oct 2017 00:04:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966627AbdJRHEN (ORCPT + 27 others); Wed, 18 Oct 2017 03:04:13 -0400 Received: from foss.arm.com ([217.140.101.70]:33672 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966601AbdJRHEI (ORCPT ); Wed, 18 Oct 2017 03:04:08 -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 90D1515BE; Wed, 18 Oct 2017 00:04:07 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 763543F590; Wed, 18 Oct 2017 00:03:59 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 09/20] crypto: move drbg to generic async completion Date: Wed, 18 Oct 2017 08:00:41 +0100 Message-Id: <1508310057-25369-10-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DRBG is starting an async. crypto op and waiting for it complete. Move it over to generic code doing the same. The code now also passes CRYPTO_TFM_REQ_MAY_SLEEP flag indicating crypto request memory allocation may use GFP_KERNEL which should be perfectly fine as the code is obviously sleeping for the completion of the request any way. Signed-off-by: Gilad Ben-Yossef --- crypto/drbg.c | 36 +++++++++--------------------------- include/crypto/drbg.h | 3 +-- 2 files changed, 10 insertions(+), 29 deletions(-) -- 2.7.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index 7001839..4faa278 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 Wed Oct 18 07:00: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: 116220 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5744774qgn; Wed, 18 Oct 2017 00:04:29 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBqrci0wcWrqtDaxVJl/JH8G78grZ5AlKMXEyo0isRubDYyubeNkw+W2EQoRmtzS4zPXlca X-Received: by 10.101.74.193 with SMTP id c1mr13171789pgu.260.1508310269234; Wed, 18 Oct 2017 00:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310269; cv=none; d=google.com; s=arc-20160816; b=L3v7k0eo4amRi/m6dlJqEfMYtc+vf3DmtM8Rt6LQ0jZ54Lvk3bzu/i7xaQbRY7aQtz wliw7qcfmqwcidk8VxNQoJV9F+gVM/jf1CC3C+Dor/8XV1syQ3hei/RedSJJEmeFG5YJ Y0veCXhaC2scxUXZiERkOvEB09fBc2qNUtDpB7KgCkSxvKs8IxO+p9UWpVEulWWPnPw9 thgaELlu/kcdCUoHtNQoCN/Zxb3FVO3dpED6io+AKdEa6NSOI0L1xnvDeVk+Esw/yIyc 5y/T3qyEC/16d5sIKHDCYSk0d35NaRPW9gTbzIaSBFqZlm60LlkPrBHxVhVHQPA0JWz9 HM3g== 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=MfZrwxucL22mKAcu7KqCue81zlD8VRpnG42XZPur3jQ=; b=v7TrXeNsJsmXxpMkI2004h6uztypeQcOunEvIsjAv7quLtv8ydqLxhBAaIsppKKoca TnNLNOrW7IMCXYclUzs0eGyl2gNLd07NrWrlSjD8WiiJ1lfOzby6fvov4vcjk8sSqZRM qLJkpDru3cYSVE0IVlSRYcI/pVPSFnyTMsAX/zvpp4RKoRkmYkzxqff7C5zfIB5w7+B9 Ql4Lr3PBz9yKp5erJRfo3gzt5yjv5IanUQuDeBwbzK9QCqP9TE2RSYrO+3xA73Xy7oOO hAXbIe+TcubA6f8Uam8LBas5BHMiFbiMBqsI4RBwv6etZF/Ws+MKtXEY5RDhRreFnYIH MsBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u13si6540664pgq.234.2017.10.18.00.04.28; Wed, 18 Oct 2017 00:04:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966653AbdJRHE0 (ORCPT + 27 others); Wed, 18 Oct 2017 03:04:26 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33716 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966601AbdJRHEV (ORCPT ); Wed, 18 Oct 2017 03:04:21 -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 569591529; Wed, 18 Oct 2017 00:04:21 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3AAA73F590; Wed, 18 Oct 2017 00:04:13 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 10/20] crypto: move gcm to generic async completion Date: Wed, 18 Oct 2017 08:00:42 +0100 Message-Id: <1508310057-25369-11-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.4 diff --git a/crypto/gcm.c b/crypto/gcm.c index 80cf6cf..8589681 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -17,7 +17,6 @@ #include #include #include "internal.h" -#include #include #include #include @@ -79,11 +78,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; @@ -99,17 +93,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) { @@ -120,7 +103,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; @@ -141,21 +124,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 Wed Oct 18 07:00: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: 116224 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5745318qgn; Wed, 18 Oct 2017 00:05:12 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T/OrdC9zvW4r9E7CMSVYT+FB4esIb+7Pc4G90dLILDbVoJylfDsBCpoOEKc3D+mJJh5jW8 X-Received: by 10.84.131.197 with SMTP id d63mr8829598pld.414.1508310312579; Wed, 18 Oct 2017 00:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310312; cv=none; d=google.com; s=arc-20160816; b=YF3AQ72EEcIIUKkTwsPvcS7aXoC+jbZ4GCR7liIcQJCMWBiw7Kv2WJYWRxtICHB2Al oc8NMvlBlKpnrY8E61c70O001tjQjo+n3ah6skLe0rG06GhcW5X4kOoIBQSRrCTytUJM Xi8BeLxhVCQYck2VB45t9JmoLADUFqhY2EKYyxLH6DbRVM01sZktxDLtDg3X+E+RIPVE Fb4GEY3EWMdfZqR8W66b1PwuQwgPG7B1keotOGuMGQixTX9OJ0H18AAY1RXFFNIhZBps HSxzL+ibyMZvN8Qwmt/0mda2FBHmhVtYSphSwtMz7lpo92YiVcZyxo+5Q8+2nlA4ZRm/ i1VA== 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=fPrCh5CYVqixVDSjwgiyMrEoZs4SPP1LfH1Q+/EFb2E=; b=NLoYymdPjJ2uenZvPvnSbVErb9joE2WEtkwHTOLAKyfyeD/3Xc6xwpK4ujlrGFYutT NxzO6XkNnIkqMc/+y3L9BRGGXR4OB7TkRsH2R5rWrN8kunRv6HTWwHwRMAp2COI7n9Ou iQWlQXZ+lyJ0gkygYHmxoWiBSHanQSQNL1pL9W4DTX6cdUBsNCNSkqtQ8E+PuZ+Nuaju +wGT7tq2jSNFVmECgPiUevj+6UiMl38SBx9FPfbz63lzvK7Ww51UE7rO2++oGZDaJXWB BJla+PDfFPrvjVVxcchHklDpi0Fl5O9nlws90kDRZLlmn11MtBd2zx3vTGzJVOfVh0tz od1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si7288717plh.27.2017.10.18.00.05.12; Wed, 18 Oct 2017 00:05:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966750AbdJRHFK (ORCPT + 27 others); Wed, 18 Oct 2017 03:05:10 -0400 Received: from foss.arm.com ([217.140.101.70]:33888 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966527AbdJRHFE (ORCPT ); Wed, 18 Oct 2017 03:05:04 -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 1BD91165D; Wed, 18 Oct 2017 00:05:04 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8DACA3F590; Wed, 18 Oct 2017 00:04:55 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , Mikulas Patocka , 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-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 Subject: [PATCH v10 13/20] dm: move dm-verity to generic async completion Date: Wed, 18 Oct 2017 08:00:45 +0100 Message-Id: <1508310057-25369-14-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dm-verity is starting async. crypto ops and waiting for them to complete. Move it over to generic code doing the same. This also avoids a future potential data coruption bug created by the use of wait_for_completion_interruptible() without dealing correctly with an interrupt aborting the wait prior to the async op finishing, should this code ever move to a context where signals are not masked. Signed-off-by: Gilad Ben-Yossef CC: Mikulas Patocka --- drivers/md/dm-verity-target.c | 81 +++++++++++-------------------------------- drivers/md/dm-verity.h | 5 --- 2 files changed, 20 insertions(+), 66 deletions(-) -- 2.7.4 diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index bda3cac..811ad28 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -92,74 +92,33 @@ static sector_t verity_position_at_level(struct dm_verity *v, sector_t block, return block >> (level * v->hash_per_block_bits); } -/* - * Callback function for asynchrnous crypto API completion notification - */ -static void verity_op_done(struct crypto_async_request *base, int err) -{ - struct verity_result *res = (struct verity_result *)base->data; - - if (err == -EINPROGRESS) - return; - - res->err = err; - complete(&res->completion); -} - -/* - * Wait for async crypto API callback - */ -static inline int verity_complete_op(struct verity_result *res, int ret) -{ - switch (ret) { - case 0: - break; - - case -EINPROGRESS: - case -EBUSY: - ret = wait_for_completion_interruptible(&res->completion); - if (!ret) - ret = res->err; - reinit_completion(&res->completion); - break; - - default: - DMERR("verity_wait_hash: crypto op submission failed: %d", ret); - } - - if (unlikely(ret < 0)) - DMERR("verity_wait_hash: crypto op failed: %d", ret); - - return ret; -} - static int verity_hash_update(struct dm_verity *v, struct ahash_request *req, const u8 *data, size_t len, - struct verity_result *res) + struct crypto_wait *wait) { struct scatterlist sg; sg_init_one(&sg, data, len); ahash_request_set_crypt(req, &sg, NULL, len); - return verity_complete_op(res, crypto_ahash_update(req)); + return crypto_wait_req(crypto_ahash_update(req), wait); } /* * Wrapper for crypto_ahash_init, which handles verity salting. */ static int verity_hash_init(struct dm_verity *v, struct ahash_request *req, - struct verity_result *res) + struct crypto_wait *wait) { int r; ahash_request_set_tfm(req, v->tfm); ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG, - verity_op_done, (void *)res); - init_completion(&res->completion); + crypto_req_done, (void *)wait); + crypto_init_wait(wait); - r = verity_complete_op(res, crypto_ahash_init(req)); + r = crypto_wait_req(crypto_ahash_init(req), wait); if (unlikely(r < 0)) { DMERR("crypto_ahash_init failed: %d", r); @@ -167,18 +126,18 @@ static int verity_hash_init(struct dm_verity *v, struct ahash_request *req, } if (likely(v->salt_size && (v->version >= 1))) - r = verity_hash_update(v, req, v->salt, v->salt_size, res); + r = verity_hash_update(v, req, v->salt, v->salt_size, wait); return r; } static int verity_hash_final(struct dm_verity *v, struct ahash_request *req, - u8 *digest, struct verity_result *res) + u8 *digest, struct crypto_wait *wait) { int r; if (unlikely(v->salt_size && (!v->version))) { - r = verity_hash_update(v, req, v->salt, v->salt_size, res); + r = verity_hash_update(v, req, v->salt, v->salt_size, wait); if (r < 0) { DMERR("verity_hash_final failed updating salt: %d", r); @@ -187,7 +146,7 @@ static int verity_hash_final(struct dm_verity *v, struct ahash_request *req, } ahash_request_set_crypt(req, NULL, digest, 0); - r = verity_complete_op(res, crypto_ahash_final(req)); + r = crypto_wait_req(crypto_ahash_final(req), wait); out: return r; } @@ -196,17 +155,17 @@ int verity_hash(struct dm_verity *v, struct ahash_request *req, const u8 *data, size_t len, u8 *digest) { int r; - struct verity_result res; + struct crypto_wait wait; - r = verity_hash_init(v, req, &res); + r = verity_hash_init(v, req, &wait); if (unlikely(r < 0)) goto out; - r = verity_hash_update(v, req, data, len, &res); + r = verity_hash_update(v, req, data, len, &wait); if (unlikely(r < 0)) goto out; - r = verity_hash_final(v, req, digest, &res); + r = verity_hash_final(v, req, digest, &wait); out: return r; @@ -389,7 +348,7 @@ int verity_hash_for_block(struct dm_verity *v, struct dm_verity_io *io, * Calculates the digest for the given bio */ int verity_for_io_block(struct dm_verity *v, struct dm_verity_io *io, - struct bvec_iter *iter, struct verity_result *res) + struct bvec_iter *iter, struct crypto_wait *wait) { unsigned int todo = 1 << v->data_dev_block_bits; struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); @@ -414,7 +373,7 @@ int verity_for_io_block(struct dm_verity *v, struct dm_verity_io *io, */ sg_set_page(&sg, bv.bv_page, len, bv.bv_offset); ahash_request_set_crypt(req, &sg, NULL, len); - r = verity_complete_op(res, crypto_ahash_update(req)); + r = crypto_wait_req(crypto_ahash_update(req), wait); if (unlikely(r < 0)) { DMERR("verity_for_io_block crypto op failed: %d", r); @@ -482,7 +441,7 @@ static int verity_verify_io(struct dm_verity_io *io) struct dm_verity *v = io->v; struct bvec_iter start; unsigned b; - struct verity_result res; + struct crypto_wait wait; for (b = 0; b < io->n_blocks; b++) { int r; @@ -507,17 +466,17 @@ static int verity_verify_io(struct dm_verity_io *io) continue; } - r = verity_hash_init(v, req, &res); + r = verity_hash_init(v, req, &wait); if (unlikely(r < 0)) return r; start = io->iter; - r = verity_for_io_block(v, io, &io->iter, &res); + r = verity_for_io_block(v, io, &io->iter, &wait); if (unlikely(r < 0)) return r; r = verity_hash_final(v, req, verity_io_real_digest(v, io), - &res); + &wait); if (unlikely(r < 0)) return r; diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h index a59e0ad..b675bc0 100644 --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -90,11 +90,6 @@ struct dm_verity_io { */ }; -struct verity_result { - struct completion completion; - int err; -}; - static inline struct ahash_request *verity_io_hash_req(struct dm_verity *v, struct dm_verity_io *io) { From patchwork Wed Oct 18 07:00:46 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: 116225 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5745493qgn; Wed, 18 Oct 2017 00:05:25 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDqQlMFU/8956IXx/vSutAw2b9Xs/Bl9OCgV6DDn39Gzzq757chAOAHK3l+rrOdxymReUGQ X-Received: by 10.99.109.79 with SMTP id i76mr13334895pgc.134.1508310325626; Wed, 18 Oct 2017 00:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310325; cv=none; d=google.com; s=arc-20160816; b=R/onIm+cV67gH6u0TlZiEEu+B9ZG2DSsPy4J4WyhSLyghDRB+L0WXwC7/4K1nMWY5M 2cluDoemHDIAepriFBwnRltYKaErzMNIHuHFj5HWN2vesoXGJVfN9lY4eU56LEsbCduM 7mc93ICnYAcqLhJ6V9LxuPJEIOLlFWVpZs9EhNz+p11NL4mVE8XvRnNQYu94ASpU1TAZ TMx+X0cuRUKSWYqSlnndbO5JtEsa+huh+UUHnwkkflwF3EhtvIRCTANCmTCJ6XSpCo5X ooUZr8/W/04iHQLJdCkiHq6r6jIO3sGQGFBp2Q42cw5rjm1We2pvPDq5wek7B41SRxoB NZ7g== 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=u3XMNwqRFqe0XhjHVtK3DWh/IPAkmsWcn4TJoVlgkSE=; b=i/uDl1f2AIlX+16O8Vdrhnu2acr13pWU/Oo4n/E5EcExvjmedKo2j9IX8MGkV4mbkf iQcECtFD1ggfU5opC+7Vxp1MNnPRaCI6D8gdsEKlh1IJgPRCUoj+WjVxx7x7YFi4FY53 n3RFJT3VJV4jQ45PkOnmqoUNbS8seeFdJhK+FtAVfTwwKBwJzJjVFF9cFSuYC35m/m6r loRj+FCz8ONXNS2E+zGakj4zBrlWReXPffW4buFruH0uvb9oH8julsyjlikRP9wA2WnN FB/rtDuAv5GnePiLECmtXx9SRSqPOcllRJD3LBNnKeCzYtC0iXcW5ncDahZgNamK6PpT f+zQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si1994987pga.745.2017.10.18.00.05.25; Wed, 18 Oct 2017 00:05:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966776AbdJRHFX (ORCPT + 27 others); Wed, 18 Oct 2017 03:05:23 -0400 Received: from foss.arm.com ([217.140.101.70]:33942 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966527AbdJRHFS (ORCPT ); Wed, 18 Oct 2017 03:05:18 -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 1F02815BE; Wed, 18 Oct 2017 00:05:18 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C135C3F590; Wed, 18 Oct 2017 00:05: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 14/20] cifs: move to generic async completion Date: Wed, 18 Oct 2017 08:00:46 +0100 Message-Id: <1508310057-25369-15-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.4 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index bdb963d..e067404 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2087,22 +2087,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) { @@ -2143,12 +2127,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__, @@ -2208,14 +2190,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 Wed Oct 18 07:00: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: 116226 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5745665qgn; Wed, 18 Oct 2017 00:05:39 -0700 (PDT) X-Google-Smtp-Source: AOwi7QABE2QweQV+MWD/KV7OG4mis57EIXyqcEqOFyHjqvwon6IMq7cwczLzg5KN2jFFyIIKAHWT X-Received: by 10.84.140.235 with SMTP id 98mr14698299plt.428.1508310338999; Wed, 18 Oct 2017 00:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310338; cv=none; d=google.com; s=arc-20160816; b=NpMvyk/Z93AUQrXwFLYXDJWcVhTaRvi9nawT9sbj3coxSVwWSGPJGzkKvFCKrxtYrz S4sPeqM7b92hC21lJPXpEAchOQhzmjvNWRxZ9tk7BhFCCbWptHysz9ud4tit4PiEb+n/ n19vVricUm0d5rryiUQb5JWdi5APB60Et3St4H/NdOX6Z6WUgCD6IspwfibVgROy5AOm /YNDoRC+l7eDVjrPY6y2Gwl68nLlsgphpEAUdrNcSIQOPkNufczNlz9Cu1c8pK4jbhzX /CGCAmdK5D1CY9TzSPK3USqfSKVjn96nlXVz9a2bSI8muNVkRC2tHn7uQE9NbbXFMBfr IEaw== 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=um5ABAYYNjuVQxtUj1hleen9zWtB4OChRJRme2UNLrg=; b=GmjtTHZ6JNprT347XuouUYPd4D9W16y6C+a0+8eZg9N+u2iyl7yj5Ngq93nZJ4Vqvt n/3leZIvw7hKvuMYEpe5+iUeKaGFRuvnXsvE4WnOIYvovGB+S1K+TqavKMGJkc1uUeeS 6WvZiuE9e3HuYH99uzNbYt7ujxHJh+IroO+xm48NXeq4gnZuVLCR6uFLnWLiopku0M/z ZTvb6iBi493yqyqqynB28FextO4WeNCfA0CR8EhtzNPjdc3UIkaMTv08B6d2LAQgTLrF y0pa4Od9ZEJ1WJJYq4mbV1QxMbEQJpTypDek3wfZMyvG9m1sn3sH3dpuya5F87MRxew2 TSfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si1994987pga.745.2017.10.18.00.05.38; Wed, 18 Oct 2017 00:05:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966804AbdJRHFh (ORCPT + 27 others); Wed, 18 Oct 2017 03:05:37 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33996 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966527AbdJRHFc (ORCPT ); Wed, 18 Oct 2017 03:05:32 -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 E6D301529; Wed, 18 Oct 2017 00:05:31 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C166E3F590; Wed, 18 Oct 2017 00:05: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 15/20] ima: move to generic async completion Date: Wed, 18 Oct 2017 08:00:47 +0100 Message-Id: <1508310057-25369-16-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ima 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: Mimi Zohar --- security/integrity/ima/ima_crypto.c | 56 +++++++++++-------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) -- 2.7.4 diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index a856d8c..9057b16 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -27,11 +27,6 @@ #include "ima.h" -struct ahash_completion { - struct completion completion; - int err; -}; - /* minimum file size for ahash use */ static unsigned long ima_ahash_minsize; module_param_named(ahash_minsize, ima_ahash_minsize, ulong, 0644); @@ -196,30 +191,13 @@ static void ima_free_atfm(struct crypto_ahash *tfm) crypto_free_ahash(tfm); } -static void ahash_complete(struct crypto_async_request *req, int err) +static inline int ahash_wait(int err, struct crypto_wait *wait) { - struct ahash_completion *res = req->data; - if (err == -EINPROGRESS) - return; - res->err = err; - complete(&res->completion); -} + err = crypto_wait_req(err, wait); -static int ahash_wait(int err, struct ahash_completion *res) -{ - switch (err) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - wait_for_completion(&res->completion); - reinit_completion(&res->completion); - err = res->err; - /* fall through */ - default: + if (err) pr_crit_ratelimited("ahash calculation failed: err: %d\n", err); - } return err; } @@ -233,7 +211,7 @@ static int ima_calc_file_hash_atfm(struct file *file, int rc, read = 0, rbuf_len, active = 0, ahash_rc = 0; struct ahash_request *req; struct scatterlist sg[1]; - struct ahash_completion res; + struct crypto_wait wait; size_t rbuf_size[2]; hash->length = crypto_ahash_digestsize(tfm); @@ -242,12 +220,12 @@ static int ima_calc_file_hash_atfm(struct file *file, if (!req) return -ENOMEM; - init_completion(&res.completion); + crypto_init_wait(&wait); ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - ahash_complete, &res); + crypto_req_done, &wait); - rc = ahash_wait(crypto_ahash_init(req), &res); + rc = ahash_wait(crypto_ahash_init(req), &wait); if (rc) goto out1; @@ -288,7 +266,7 @@ static int ima_calc_file_hash_atfm(struct file *file, * read/request, wait for the completion of the * previous ahash_update() request. */ - rc = ahash_wait(ahash_rc, &res); + rc = ahash_wait(ahash_rc, &wait); if (rc) goto out3; } @@ -304,7 +282,7 @@ static int ima_calc_file_hash_atfm(struct file *file, * read/request, wait for the completion of the * previous ahash_update() request. */ - rc = ahash_wait(ahash_rc, &res); + rc = ahash_wait(ahash_rc, &wait); if (rc) goto out3; } @@ -318,7 +296,7 @@ static int ima_calc_file_hash_atfm(struct file *file, active = !active; /* swap buffers, if we use two */ } /* wait for the last update request to complete */ - rc = ahash_wait(ahash_rc, &res); + rc = ahash_wait(ahash_rc, &wait); out3: if (read) file->f_mode &= ~FMODE_READ; @@ -327,7 +305,7 @@ static int ima_calc_file_hash_atfm(struct file *file, out2: if (!rc) { ahash_request_set_crypt(req, NULL, hash->digest, 0); - rc = ahash_wait(crypto_ahash_final(req), &res); + rc = ahash_wait(crypto_ahash_final(req), &wait); } out1: ahash_request_free(req); @@ -537,7 +515,7 @@ static int calc_buffer_ahash_atfm(const void *buf, loff_t len, { struct ahash_request *req; struct scatterlist sg; - struct ahash_completion res; + struct crypto_wait wait; int rc, ahash_rc = 0; hash->length = crypto_ahash_digestsize(tfm); @@ -546,12 +524,12 @@ static int calc_buffer_ahash_atfm(const void *buf, loff_t len, if (!req) return -ENOMEM; - init_completion(&res.completion); + crypto_init_wait(&wait); ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, - ahash_complete, &res); + crypto_req_done, &wait); - rc = ahash_wait(crypto_ahash_init(req), &res); + rc = ahash_wait(crypto_ahash_init(req), &wait); if (rc) goto out; @@ -561,10 +539,10 @@ static int calc_buffer_ahash_atfm(const void *buf, loff_t len, ahash_rc = crypto_ahash_update(req); /* wait for the update request to complete */ - rc = ahash_wait(ahash_rc, &res); + rc = ahash_wait(ahash_rc, &wait); if (!rc) { ahash_request_set_crypt(req, NULL, hash->digest, 0); - rc = ahash_wait(crypto_ahash_final(req), &res); + rc = ahash_wait(crypto_ahash_final(req), &wait); } out: ahash_request_free(req); From patchwork Wed Oct 18 07:00: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: 116227 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5745845qgn; Wed, 18 Oct 2017 00:05:54 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA9UsPPScTX7bfKL9ErczjoPkYYfYa0Gt4At/vluMk+ONB0vQ7rDB6uxekA3JbXZytFrjaY X-Received: by 10.159.218.142 with SMTP id w14mr14732160plp.310.1508310354418; Wed, 18 Oct 2017 00:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310354; cv=none; d=google.com; s=arc-20160816; b=Lnj9OcpF95/zl0Edfcn1KSLJtEQbrn2IyWUYMQLzpDSC8XxwtnozcEXJ1sosbPuYXq vO/BRgoJ3I9F3PjkLWy5L8DOiQKSYzspm35a+vkOKwyA3xYpPydBqzrl6NT7kGxRfQlP vRKdTMi3oNboBBFNK+DM2ZpsXGPYxRKp7WyoBIz/XF2HyoK3SJX22SSdofUYwM6FTpKW Hp+vSWqKAE2ZRHV3QNuX2Uf9qSqgb+GgFvnSD3rfa+Rih7SogoiE14tYzU3BxeGJeIbY ZEoJJTfFd9hk7PLqSJBq2glshncvSuDZJCJYIb2lfluC7yb3vsklxyhPAFs/t3EIe+ld pyOg== 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=ueHv8mUb8y+XiT0hkkwxzzuZ7i3ZyXnu0dh6C1qXJ8I=; b=KxXNPNKNWZu+QE9ay4y8eAtRQb9cIcK6D0f/KK7yMeDKJat2Uw/POBh4kmP+xJAF4r iKdmFVR8oJFrcu030pnMDKWOFCm1+tMea65OH36RKQDGytNf8VQjFs/y8r9UPNKoCc7H m0FtlQ+30pw78zO5Jp2nN4ZYZ8rHm2HLMsNU536ss2U7/KrlfiZueGVbK6Qye+Rx+BUw M6L7RH7TlGZEUQ415FFiH4lj388nSnjS+hUMbxMq9Ey7twmnMPW0fjyy+TEBvtwjkFe9 m0zuEX5fG9taP+f0N7WLrcBfv86dUx8xdj1IHHcsc4k1wXZnQ+juoJkg58n8/FFQGypC XgTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b61si5972906plb.488.2017.10.18.00.05.54; Wed, 18 Oct 2017 00:05:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966827AbdJRHFv (ORCPT + 27 others); Wed, 18 Oct 2017 03:05:51 -0400 Received: from foss.arm.com ([217.140.101.70]:34054 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761310AbdJRHFr (ORCPT ); Wed, 18 Oct 2017 03:05:47 -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 A5E2915BE; Wed, 18 Oct 2017 00:05:46 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 947FA3F590; Wed, 18 Oct 2017 00:05: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 16/20] crypto: tcrypt: move to generic async completion Date: Wed, 18 Oct 2017 08:00:48 +0100 Message-Id: <1508310057-25369-17-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.4 diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index a371c072..7fa7047 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 { @@ -396,21 +373,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]; }; @@ -439,7 +411,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) { @@ -448,8 +420,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); } @@ -491,16 +463,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(); @@ -678,7 +650,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; @@ -707,9 +679,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) @@ -764,15 +736,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, @@ -852,7 +818,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; @@ -865,7 +831,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); @@ -886,7 +852,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 Wed Oct 18 07:00: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: 116228 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5746052qgn; Wed, 18 Oct 2017 00:06:08 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QnNRKHwcu8yU99oWB3Xr94gUPmwEw+L7XC5tYDhQFHZlnDP39ownZqkkd93AaqjhkJ1vej X-Received: by 10.84.128.99 with SMTP id 90mr4104976pla.171.1508310368663; Wed, 18 Oct 2017 00:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310368; cv=none; d=google.com; s=arc-20160816; b=rzddeBCX7mJXnQXlC88mQWDjssgY0NDtHxaNawNrE5XsmdSUQ7Sl17fnrypjKZxjWf 9iVfkdqk7jfCePF/3CH5lZ57SULzevbW26gFM5KVy4Rq2dKDn+cIyn4B/wWNSIyydYkX CCRtSSOlgcW+/pR7Pr1BJGFsONX9A3X9zhlrPP59y+V1uYp6ONjFaR6SH5g54npKdRsU yexrT9HFqu+F5Zb11BS3t0O1PnWwALqq7IAH93Ct2gL3GgF4Q9HiDQKcahKw6eYquq2m 17fvAQjkhhLFuGIl93qJBmBimOD9RjFKCcBC7ZzvWVEaARt9OLTxOvKD+nooxEuFzS// u+cA== 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=zcf4eRoEQo+FSDjzYup4ElRpo5mz7aTje8xWHWO8fIQ=; b=X36yySM2I29jJq0I+GY0jdwuj75ndcPyjg/EUtHcCDKn4eRD1eQg+DCU5R20GAgHEA ICsg7jXpGkhv4+eER8iIB6xGCWTTBAvztgwU7SdwUHB3wxucpyx/ixp1RA977R05soKZ WSh52SU7Ogh5mB3pzlKYiREelj3sRdlcQ9V/EX/6pBow9R9IcAxopMK5U1t2d8i7GlA0 bqhu8mFddKOlVSG9AoG2TXuPs2H37zt+ZYXkiKrlwPf+bX2yAG8CDCZwJzRSHVHdk5Qw hhYFP7LGvf8cQHGQ5r+l8ZGPadnzxmnAUqW0slrftMswi8NdjOBBAMSeyvtP0hOGDklR pecg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24si6576163pge.245.2017.10.18.00.06.08; Wed, 18 Oct 2017 00:06:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966852AbdJRHGG (ORCPT + 27 others); Wed, 18 Oct 2017 03:06:06 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34114 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761369AbdJRHGB (ORCPT ); Wed, 18 Oct 2017 03:06:01 -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 B726BF; Wed, 18 Oct 2017 00:06:00 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 713593F590; Wed, 18 Oct 2017 00:05:52 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 17/20] crypto: talitos: move to generic async completion Date: Wed, 18 Oct 2017 08:00:49 +0100 Message-Id: <1508310057-25369-18-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Tested-by: Christophe Leroy --- drivers/crypto/talitos.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) -- 2.7.4 diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 5bd8191..9c80e0c 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -2160,22 +2160,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) { @@ -2183,10 +2167,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) @@ -2195,25 +2179,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 Wed Oct 18 07:00: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: 116229 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5746239qgn; Wed, 18 Oct 2017 00:06:23 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB6zGKDyGP9ZDs3PsbeuUUv/wktVcRZ4CXXPPq3jpIirYYNLT8QX0YyeczVy7PRCitBK6GT X-Received: by 10.99.111.65 with SMTP id k62mr12591128pgc.56.1508310383825; Wed, 18 Oct 2017 00:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310383; cv=none; d=google.com; s=arc-20160816; b=cpSJ9sBYW/MiK5fLlgHHGnXn5VuSBZmcrh+mwId0pDgfWqn1MfpdHvY7B7NL0PJ+bo 6mVa+i/GkCljKtiaQcT6xGJdHYy5k0iusX4j2EpOIg8eI09R7lTxbPPXik9AyqUfG0Ir CCXzlyWfk+TrtuVRRuXqGX2YVqLWB6H9+Mr9cN8sDLb139gJpTyXExgbWuaF4lNZPiqB tQa77xdUSlV4KnrJoZtcfOnIUXjznlbfvc1CUchLJdoddiOKhE6LVYFoySAJigbd2g4Z lDVp1FopXPhw2ksTOebi29TEAYtUhXGxQJOuPvJF2aGqnvFNaXhfZLKKvKAlgScfCY+P TNog== 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=qMMe51WYIxsnTlBJLya4v4/BwQ/aJkvc/8TOHu3rvN4=; b=bVvULsCoDxoU56J/+CfySarEteskVJu+lcZj7zckiO2pPzbPgvztfsQ7pzlwgp34IJ y7oP4bwpg8mv+jLPZzaUtz2UO7CHq9W/MJBxWFsbuPl14bwXBtLxlzx1YEslWC/b2IgO sgOuEPNv0DVROoD9512NUjgcHu3Tev1ONhZ1/IMqLJBKM54sA625oIpRcm3GSgNxkDWn u3HQQFseB0agfnPnfPks7PTIAP1IRrnLdzjS9D2ei+MbaGOrd6PlfLB16GHOmdsEXLR3 I7b3u3AT33C73LT0C3xyuZftK/6sR6dwicjgKZzr02xWyqqyWAYhwov65wFHYHccm6F5 kDPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g59si7311612plb.583.2017.10.18.00.06.23; Wed, 18 Oct 2017 00:06:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966875AbdJRHGV (ORCPT + 27 others); Wed, 18 Oct 2017 03:06:21 -0400 Received: from foss.arm.com ([217.140.101.70]:34168 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761395AbdJRHGQ (ORCPT ); Wed, 18 Oct 2017 03:06: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 390E915BE; Wed, 18 Oct 2017 00:06:16 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D62793F590; Wed, 18 Oct 2017 00:06:07 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 18/20] crypto: qce: move to generic async completion Date: Wed, 18 Oct 2017 08:00:50 +0100 Message-Id: <1508310057-25369-19-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.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 Wed Oct 18 07:00: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: 116230 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5746394qgn; Wed, 18 Oct 2017 00:06:38 -0700 (PDT) X-Google-Smtp-Source: AOwi7QClP/70sdYomFEar5Fm2AWNk2ZQFVDjbSO9q+903TfjYtUt2uNpu/Njjn7KS8UooXWvONdf X-Received: by 10.84.236.12 with SMTP id q12mr14276416plk.314.1508310397913; Wed, 18 Oct 2017 00:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310397; cv=none; d=google.com; s=arc-20160816; b=z9Vpy4/5A/gQsAd1kAkA6hBiHyJZc1LZVoTXAxQ17NY7Z9Rbk9PlaUasMWVmGQJ1YY G9kmvvPDF0KPlp/xH3blLqpLeve4PvFS99NAdjjM4+938+VluY+fNJJrpypZJrNr3+Hq Sd44zawMZcNrORLGMQXujt8nsVhvvwxOCucaWmGBE3JEqK56uNNV17PwDNRiIB7rjXRL uKITAjUnF5QkZIxOEi7pX8snnGjsO8xkNnsBzfug9IDzAQNY+OPNf5vTOI+i7IMNx1id L4Po7TdI3TrBpVs3PT/qa3xgeq4IsVpnTaqjmW61BxRPVHeWG/dWxkBxKdwBvUzK4MQ9 YTIQ== 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=Ux8kW1Be35okv7ZpIihY85HrHpN1sgkI6gJXZ907llg=; b=qGYoO0LL18nBQxK3hYtoPyjvnT6JJEcnUbbl4+5e2Wu9bLwuAibtwDhk+gaoBrFiOL vor1UAkC2wswPG0kXJiUKSeZRm3kbTV/bN0nocSdatUdGtCAbVfHFZ5eJgXPACbeSDTz Hkh+ALU0tbR8IBhujPiUXu/HQgJXxRxmPxYm9oqidR3rKYi4J7JESiJeJNoIjWYmL5Q8 N8P8oi86mP0YmNSsFqXM86G9RJhStyMuBvAbKH7d8mpNBbggVq53TiEk+lFmhewNL37g CgOab/D/Ys/lh0x1gYEry8RDAUHV1RJ8yqgIhVbcy1RaTFsfSzVosV2Pk2ixawLAAeXQ NXeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s64si6924709pfe.463.2017.10.18.00.06.37; Wed, 18 Oct 2017 00:06:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966901AbdJRHGg (ORCPT + 27 others); Wed, 18 Oct 2017 03:06:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34232 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761436AbdJRHGb (ORCPT ); Wed, 18 Oct 2017 03:06:31 -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 12C11165D; Wed, 18 Oct 2017 00:06:31 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B2B223F590; Wed, 18 Oct 2017 00:06:22 -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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 19/20] crypto: mediatek: move to generic async completion Date: Wed, 18 Oct 2017 08:00:51 +0100 Message-Id: <1508310057-25369-20-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.7.4 diff --git a/drivers/crypto/mediatek/mtk-aes.c b/drivers/crypto/mediatek/mtk-aes.c index 32aa587..c2058cf 100644 --- a/drivers/crypto/mediatek/mtk-aes.c +++ b/drivers/crypto/mediatek/mtk-aes.c @@ -138,11 +138,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 */ @@ -942,17 +937,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 @@ -968,7 +952,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; @@ -1008,22 +992,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; From patchwork Wed Oct 18 07:00:52 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: 116231 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp5746548qgn; Wed, 18 Oct 2017 00:06:51 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAK2WJ1n1QU66j/ub7hnp6re7X1Z1vnjZW3YVcivUsA2JlQTxFc093HJhNHplzjlDvg7zhu X-Received: by 10.98.198.195 with SMTP id x64mr14079294pfk.322.1508310411582; Wed, 18 Oct 2017 00:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508310411; cv=none; d=google.com; s=arc-20160816; b=sfheLKUY2qdQZqqckMvsDJm7KK0QItuzjIaJXdj7f0kPVQ2FQGCsGKiKZgWr33EW4B a7ML3WvfNTBgrCQM3eBWJpseScIpi/zmiqNw6tVkJpFTt/CpVLALH5inx+xcCzoOaGCY xjQiUlkJQiNEis5HM2EMJv9hnyb0JtvNvyMzIZ6EF1U9zXRzR6ehAwkMP/BkDn/2DhqS Czxyqt3mJCIsGCpFy1HKMjXPEK59VAc8/2e8tDkKSX0f0AzN9r0vQfTwPmkLbdFf12Kx gOX6b0aJ2oCE7V9xiTKwYPEjyGanDrw1suMIeQC5WvvpMMpleliiTG9e/X5bcUtz2v63 VWmw== 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=GC236wveax5YSzj+Bhh0LelivQd+qYwt8ZP+Zmr+cKs=; b=GJXlFn0CFZEkzYpsA/470gFYOSa8NvyDW8pfP/7k1BkLi9zvOkGpFmjbzjYVTGfvXi h4wO/tMXyw4rUioCowOktFYgEmxCyddKwLl3mGjUPKJcfNU3uwAS11QK2wgv8Y1Z6bTl JXKg+/S8YHfn0rt4cMWhSrMD72/9B7xE5MLy7+VOq3/7+It9FCPV990j51FuCRjcsDXZ RgPUOYpUq5/PKfbTUsSkoAcgQnFadbTDXYpVWlv411RjgPT3cd2fcUi91mCIDsKCc+U8 NFMu67VFtUE1tt0SbxzHvwr1cFtNLmDpxzxncum72H6/Aq9JKwKMgpuKUSl6eK5dRnVh cINw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v187si723783pfv.76.2017.10.18.00.06.51; Wed, 18 Oct 2017 00:06:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966926AbdJRHGt (ORCPT + 27 others); Wed, 18 Oct 2017 03:06:49 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34276 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761450AbdJRHGp (ORCPT ); Wed, 18 Oct 2017 03:06:45 -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 2EC351529; Wed, 18 Oct 2017 00:06:45 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D7C713F590; Wed, 18 Oct 2017 00:06: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, Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Steffen Klassert , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" Cc: Ofir Drang , 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-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 Subject: [PATCH v10 20/20] crypto: adapt api sample to use async. op wait Date: Wed, 18 Oct 2017 08:00:52 +0100 Message-Id: <1508310057-25369-21-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508310057-25369-1-git-send-email-gilad@benyossef.com> References: <1508310057-25369-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code sample is waiting for an async. crypto op completion. Adapt sample to use the new generic infrastructure to do the same. This also fixes a possible data coruption bug created by the use of wait_for_completion_interruptible() without dealing correctly with an interrupt aborting the wait prior to the async op finishing. Signed-off-by: Gilad Ben-Yossef --- Documentation/crypto/api-samples.rst | 52 +++++++----------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) -- 2.7.4 diff --git a/Documentation/crypto/api-samples.rst b/Documentation/crypto/api-samples.rst index 2531948..006827e 100644 --- a/Documentation/crypto/api-samples.rst +++ b/Documentation/crypto/api-samples.rst @@ -7,59 +7,27 @@ Code Example For Symmetric Key Cipher Operation :: - struct tcrypt_result { - struct completion completion; - int err; - }; - /* tie all data structures together */ struct skcipher_def { struct scatterlist sg; struct crypto_skcipher *tfm; struct skcipher_request *req; - struct tcrypt_result result; + struct crypto_wait wait; }; - /* Callback function */ - static void test_skcipher_cb(struct crypto_async_request *req, int error) - { - struct tcrypt_result *result = req->data; - - if (error == -EINPROGRESS) - return; - result->err = error; - complete(&result->completion); - pr_info("Encryption finished successfully\n"); - } - /* Perform cipher operation */ static unsigned int test_skcipher_encdec(struct skcipher_def *sk, int enc) { - int rc = 0; + int rc; if (enc) - rc = crypto_skcipher_encrypt(sk->req); + rc = crypto_wait_req(crypto_skcipher_encrypt(sk->req), &sk->wait); else - rc = crypto_skcipher_decrypt(sk->req); - - switch (rc) { - case 0: - break; - case -EINPROGRESS: - case -EBUSY: - rc = wait_for_completion_interruptible( - &sk->result.completion); - if (!rc && !sk->result.err) { - reinit_completion(&sk->result.completion); - break; - } - default: - pr_info("skcipher encrypt returned with %d result %d\n", - rc, sk->result.err); - break; - } - init_completion(&sk->result.completion); + rc = crypto_wait_req(crypto_skcipher_decrypt(sk->req), &sk->wait); + + if (rc) + pr_info("skcipher encrypt returned with result %d\n", rc); return rc; } @@ -89,8 +57,8 @@ Code Example For Symmetric Key Cipher Operation } skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - test_skcipher_cb, - &sk.result); + crypto_req_done, + &sk.wait); /* AES 256 with random key */ get_random_bytes(&key, 32); @@ -122,7 +90,7 @@ Code Example For Symmetric Key Cipher Operation /* We encrypt one block */ sg_init_one(&sk.sg, scratchpad, 16); skcipher_request_set_crypt(req, &sk.sg, &sk.sg, 16, ivdata); - init_completion(&sk.result.completion); + crypto_init_wait(&sk.wait); /* encrypt data */ ret = test_skcipher_encdec(&sk, 1);