From patchwork Sun Oct 15 09:19: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: 115865 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2528897qgn; Sun, 15 Oct 2017 02:22:47 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDwOUkF0K5yu3fDA19R2YthjOnhXQi2NdKVi4PwiDNvf8CAgBLotxU/Cv0YLG+DS1m+/qTp X-Received: by 10.98.157.156 with SMTP id a28mr5904167pfk.74.1508059367705; Sun, 15 Oct 2017 02:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508059367; cv=none; d=google.com; s=arc-20160816; b=ZZz+AOd5MXyN90ye35pRmvnUh1GzsJL9/QZ9nIs8Whd2WgbpKM6r3JZk7Bsmm0ThLr BV8SCMPhdzciPpfl1acKiH6JcOWileWxEqxpugFNkmQvJfbc1QclzFBKoENdow9zHuwa ul9sZjwTimZ56RJ4/Ig10anNWpm3CBPFoyEC8lbbw5tbrQ0rt0GPrx+EIUF7uCZXDu+Q H3lBuuEOCFdK5lOofXRGDRedHPoUsehywDr19HVCYzxhjyotQZ56WIJJPKob+wr8euuz LYZhIWF1GyNLoOCm565yAGdS/xlHdZxLM2b3lk6B19tsflHa+ONTqCDp0VxNjnmMN2dG UIhA== 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=FZgZFCaQrylKsQ5iTbrbsHZFfvtNK5s5Xi4yqKqTLbzIrI+jYcLiwu3KuFogtLOPyw gHg2a3CEc7LkMZwLkvdJwgECxFWxrzGmGUW6/HTa0dSZfL78nqDzABPI8D9fe7aEBYBl +ijb3xk04FSX3hZqSRpTd+k3SqTPcjqaY7g3P3um4Usw/7I+I8+A363PCblcQJFK65M8 wSA6E20QPXDo+Q+DDsc5M6PxNPkvkBPEXck7ox8ua8F4KTL4eUv5h8hxnePk4vOcE8P7 VpQOsV+izQl6QkTzgoJChMFLDhUUyNUmegqX42SJMoGwBy0vu/PDtb5Lkm1gZ/ebqmfr /wpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 3si51976plb.469.2017.10.15.02.22.47; Sun, 15 Oct 2017 02:22:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752213AbdJOJWq (ORCPT + 8 others); Sun, 15 Oct 2017 05:22:46 -0400 Received: from foss.arm.com ([217.140.101.70]:47460 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750753AbdJOJWl (ORCPT ); Sun, 15 Oct 2017 05:22:41 -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 78DD3169E; Sun, 15 Oct 2017 02:22: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 8878F3F3E1; Sun, 15 Oct 2017 02:22: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 , 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 v9 06/20] crypto: introduce crypto wait for async op Date: Sun, 15 Oct 2017 10:19:51 +0100 Message-Id: <1508059209-25529-7-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508059209-25529-1-git-send-email-gilad@benyossef.com> References: <1508059209-25529-1-git-send-email-gilad@benyossef.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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);