From patchwork Mon Aug 14 15:21:15 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: 110033 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4477681qge; Mon, 14 Aug 2017 08:22:59 -0700 (PDT) X-Received: by 10.99.178.86 with SMTP id t22mr24738660pgo.34.1502724179740; Mon, 14 Aug 2017 08:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502724179; cv=none; d=google.com; s=arc-20160816; b=dWi0/D4K4Sq0UidhAmYzLBFB6vt9hwVzTN/PMrbQ/Dm/rE0rbybA66Ebnhpoy/X/3v /pGNYKrTKHQAKlhaFFcknc1GXL7DavKlTIbM76M6yuAtKW5FaoVJWFaEPGlX9ajMoj2S /79BLxANgdoSqANMUNfGdo0A17W6cbeAPsHICQOWXrwqC/q4TOS+e0xCYOyQyznn43xj zKEF03eQJhAyVzHKKa+VDi+wCzZKbuHl41J1jiWWQKd+5hEXTbIDOMC9cv81M+E6DIpq +o+Kv8MFsBdud9ihNvULHixU4Frx+sTTM2nG298Kdx/vB/KEXjFL7KItviVjh0Z0d1ML TGfg== 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=IifucEGpAnq6h0w26PH6q/u7EYgLIhljH1V3XrShuys=; b=PxBpub2+DU+/gi3Wcb3wj0V7oCr19PWskobMZnIMSb/wttrADmwXflrdmfY8cLKyY8 z3KzDD02AfM7+wu169NjlZocepv8t5JXVC4fDNJZoX6nxWzpNRGt8idhGKPmF4zEvk0W UaqOYgQkOcIUCeAUGQGvTRJQfoH+s3bnacJ0ORHthS/x0eFoFg4F5N3tnRVcJ572/nLy 6sH4GVhH9G8detF+sTpOv75lUSABRauiiiiU/KKiFrWFcCE39pICe84lu4ubR0jQ1brQ qUaA8UpVoZtPETJLoYUJ+rUpHG7IuZNSa83hPpsImX1uy8vFIF71MR/774dXnp3c2os1 dE9Q== 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 v22si4251102pgo.442.2017.08.14.08.22.59; Mon, 14 Aug 2017 08:22:59 -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 S1753168AbdHNPW6 (ORCPT + 25 others); Mon, 14 Aug 2017 11:22:58 -0400 Received: from foss.arm.com ([217.140.101.70]:39760 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753117AbdHNPWx (ORCPT ); Mon, 14 Aug 2017 11:22:53 -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 3CBA61682; Mon, 14 Aug 2017 08:22:53 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B2CA3F483; Mon, 14 Aug 2017 08:22:44 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells , Tom Lendacky , Gary Hook , Boris Brezillon , Arnaud Ebalard , Matthias Brugger , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Shaohua Li , Steve French , "Theodore Y. Ts'o" , Jaegeuk Kim , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-raid@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fscrypt@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org Cc: Ofir Drang , Eric Biggers Subject: [PATCH v5 05/19] crypto: introduce crypto wait for async op Date: Mon, 14 Aug 2017 18:21:15 +0300 Message-Id: <1502724094-23305-6-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1502724094-23305-1-git-send-email-gilad@benyossef.com> References: <1502724094-23305-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 --- crypto/api.c | 13 +++++++++++++ include/linux/crypto.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) -- 2.1.4 diff --git a/crypto/api.c b/crypto/api.c index 941cd4c..2a2479d 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "internal.h" LIST_HEAD(crypto_alg_list); @@ -595,5 +596,17 @@ int crypto_has_alg(const char *name, u32 type, u32 mask) } EXPORT_SYMBOL_GPL(crypto_has_alg); +void crypto_req_done(struct crypto_async_request *req, int err) +{ + struct crypto_wait *wait = req->data; + + if (err == -EINPROGRESS) + return; + + wait->err = err; + complete(&wait->completion); +} +EXPORT_SYMBOL_GPL(crypto_req_done); + MODULE_DESCRIPTION("Cryptographic core API"); MODULE_LICENSE("GPL"); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 84da997..bb00186 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); @@ -1604,5 +1644,6 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm, src, slen, dst, dlen); } + #endif /* _LINUX_CRYPTO_H */