From patchwork Tue Aug 15 07:19:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien DESSENNE X-Patchwork-Id: 9901187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE2D860244 for ; Tue, 15 Aug 2017 07:33:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C9CB204BE for ; Tue, 15 Aug 2017 07:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 919CC287C6; Tue, 15 Aug 2017 07:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F16FB204BE for ; Tue, 15 Aug 2017 07:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sPHEOw6e6+vy1yAx6+DZkGGzH3kAsBlPr0eAt56AJpQ=; b=R6dG8vc/tRAZTg Ay3Y3FIAn3oCS9KqEgLdQCE7TVJqynK1zo+QKZaykJy9fQk+NFoYkvYtd6BkwVnQysCL3Zamzmm4b YHBhZsTDl2r1hVqg3e/rv5QfnOy+H/ol8ZM2oo0mkWJHUsy+ny+VTz8K7t91QCm+fg1pd+x2ca0xv PO9Tl2gWdZBwM/WMC/AWf4Wu3epHJhacf2hdn/ziDy7lqTJu7gYKPrus+5H6Z8EiTUhbBy7jkbf23 5mz61N8pYLtIbLGt8Y8vkATThuIkfacWuhaaP6bz8BqTbiYFjXbbwhS9/gHvXA0EtUeRrkrKQmF5z e7zowwwfZiiG6bGJQxkg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dhWLj-000107-NE; Tue, 15 Aug 2017 07:33:15 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dhW9U-00053V-Te for linux-arm-kernel@lists.infradead.org; Tue, 15 Aug 2017 07:20:40 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7F7JbGf001483; Tue, 15 Aug 2017 09:19:56 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2cbr90rywq-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 15 Aug 2017 09:19:56 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F37C43D; Tue, 15 Aug 2017 07:19:55 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C08D913B9; Tue, 15 Aug 2017 07:19:55 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.95) by Safex1hubcas22.st.com (10.75.90.92) with Microsoft SMTP Server (TLS) id 14.3.339.0; Tue, 15 Aug 2017 09:19:55 +0200 Received: from localhost (10.251.17.222) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.352.0; Tue, 15 Aug 2017 09:19:55 +0200 From: Fabien Dessenne To: Herbert Xu , "David S . Miller" , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue , , , , Subject: [PATCH v2 1/3] crypto: engine - permit to enqueue aead_request Date: Tue, 15 Aug 2017 09:19:42 +0200 Message-ID: <1502781584-18468-2-git-send-email-fabien.dessenne@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502781584-18468-1-git-send-email-fabien.dessenne@st.com> References: <1502781584-18468-1-git-send-email-fabien.dessenne@st.com> MIME-Version: 1.0 X-Originating-IP: [10.251.17.222] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-15_04:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170815_002037_254085_3F269991 X-CRM114-Status: GOOD ( 15.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lionel Debieve , Benjamin Gaignard , Ludovic Barre Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The current crypto engine allows ablkcipher_request and ahash_request to be enqueued. Extend this to aead_request. Signed-off-by: Fabien Dessenne --- crypto/crypto_engine.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ include/crypto/engine.h | 16 ++++++++ 2 files changed, 117 insertions(+) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 61e7c4e..3cdf051 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -35,6 +36,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, { struct crypto_async_request *async_req, *backlog; struct ahash_request *hreq; + struct aead_request *areq; struct ablkcipher_request *breq; unsigned long flags; bool was_busy = false; @@ -122,6 +124,22 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto req_err; } return; + case CRYPTO_ALG_TYPE_AEAD: + areq = aead_request_cast(engine->cur_req); + if (engine->prepare_aead_request) { + ret = engine->prepare_aead_request(engine, areq); + if (ret) { + pr_err("failed to prepare request: %d\n", ret); + goto req_err; + } + engine->cur_req_prepared = true; + } + ret = engine->aead_one_request(engine, areq); + if (ret) { + pr_err("failed to do aead one request from queue\n"); + goto req_err; + } + return; case CRYPTO_ALG_TYPE_ABLKCIPHER: breq = ablkcipher_request_cast(engine->cur_req); if (engine->prepare_cipher_request) { @@ -150,6 +168,10 @@ static void crypto_pump_requests(struct crypto_engine *engine, hreq = ahash_request_cast(engine->cur_req); crypto_finalize_hash_request(engine, hreq, ret); break; + case CRYPTO_ALG_TYPE_AEAD: + areq = aead_request_cast(engine->cur_req); + crypto_finalize_aead_request(engine, areq, ret); + break; case CRYPTO_ALG_TYPE_ABLKCIPHER: breq = ablkcipher_request_cast(engine->cur_req); crypto_finalize_cipher_request(engine, breq, ret); @@ -255,6 +277,48 @@ int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_transfer_hash_request_to_engine); /** + * crypto_transfer_aead_request - transfer the new request into the + * enginequeue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_aead_request(struct crypto_engine *engine, + struct aead_request *req, bool need_pump) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + + if (!engine->running) { + spin_unlock_irqrestore(&engine->queue_lock, flags); + return -ESHUTDOWN; + } + + ret = aead_enqueue_request((struct aead_queue *)&engine->queue, req); + + if (!engine->busy && need_pump) + kthread_queue_work(engine->kworker, &engine->pump_requests); + + spin_unlock_irqrestore(&engine->queue_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(crypto_transfer_aead_request); + +/** + * crypto_transfer_aead_request_to_engine - transfer one request to list + * into the engine queue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, + struct aead_request *req) +{ + return crypto_transfer_aead_request(engine, req, true); +} +EXPORT_SYMBOL_GPL(crypto_transfer_aead_request_to_engine); + +/** * crypto_finalize_cipher_request - finalize one request if the request is done * @engine: the hardware engine * @req: the request need to be finalized @@ -329,6 +393,43 @@ void crypto_finalize_hash_request(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_finalize_hash_request); /** + * crypto_finalize_aead_request - finalize one request if the request is done + * @engine: the hardware engine + * @req: the request need to be finalized + * @err: error number + */ +void crypto_finalize_aead_request(struct crypto_engine *engine, + struct aead_request *req, int err) +{ + unsigned long flags; + bool finalize_cur_req = false; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + if (engine->cur_req == &req->base) + finalize_cur_req = true; + spin_unlock_irqrestore(&engine->queue_lock, flags); + + if (finalize_cur_req) { + if (engine->cur_req_prepared && + engine->unprepare_aead_request) { + ret = engine->unprepare_aead_request(engine, req); + if (ret) + pr_err("failed to unprepare request\n"); + } + spin_lock_irqsave(&engine->queue_lock, flags); + engine->cur_req = NULL; + engine->cur_req_prepared = false; + spin_unlock_irqrestore(&engine->queue_lock, flags); + } + + req->base.complete(&req->base, err); + + kthread_queue_work(engine->kworker, &engine->pump_requests); +} +EXPORT_SYMBOL_GPL(crypto_finalize_aead_request); + +/** * crypto_engine_start - start the hardware engine * @engine: the hardware engine need to be started * diff --git a/include/crypto/engine.h b/include/crypto/engine.h index dd04c16..9ee1722 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,9 @@ * @prepare_hash_request: do some prepare if need before handle the current request * @unprepare_hash_request: undo any work done by prepare_hash_request() * @hash_one_request: do hash for current request + * @prepare_aead_request: do some prepare if need before handle the current request + * @unprepare_aead_request: undo any work done by prepare_aead_request() + * @aead_one_request: do aead for current request * @kworker: kthread worker struct for request pump * @pump_requests: work struct for scheduling work to the request pump * @priv_data: the engine private data @@ -73,10 +77,16 @@ struct crypto_engine { struct ahash_request *req); int (*unprepare_hash_request)(struct crypto_engine *engine, struct ahash_request *req); + int (*prepare_aead_request)(struct crypto_engine *engine, + struct aead_request *req); + int (*unprepare_aead_request)(struct crypto_engine *engine, + struct aead_request *req); int (*cipher_one_request)(struct crypto_engine *engine, struct ablkcipher_request *req); int (*hash_one_request)(struct crypto_engine *engine, struct ahash_request *req); + int (*aead_one_request)(struct crypto_engine *engine, + struct aead_request *req); struct kthread_worker *kworker; struct kthread_work pump_requests; @@ -94,10 +104,16 @@ int crypto_transfer_hash_request(struct crypto_engine *engine, struct ahash_request *req, bool need_pump); int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, struct ahash_request *req); +int crypto_transfer_aead_request(struct crypto_engine *engine, + struct aead_request *req, bool need_pump); +int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, + struct aead_request *req); void crypto_finalize_cipher_request(struct crypto_engine *engine, struct ablkcipher_request *req, int err); void crypto_finalize_hash_request(struct crypto_engine *engine, struct ahash_request *req, int err); +void crypto_finalize_aead_request(struct crypto_engine *engine, + struct aead_request *req, int err); int crypto_engine_start(struct crypto_engine *engine); int crypto_engine_stop(struct crypto_engine *engine); struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);