From patchwork Tue Sep 13 12:49:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 9328961 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 0D4A96077F for ; Tue, 13 Sep 2016 12:50:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A0928531 for ; Tue, 13 Sep 2016 12:50:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAE2E28E5B; Tue, 13 Sep 2016 12:50:04 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 972BF28531 for ; Tue, 13 Sep 2016 12:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755393AbcIMMuC (ORCPT ); Tue, 13 Sep 2016 08:50:02 -0400 Received: from mga06.intel.com ([134.134.136.31]:62118 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754725AbcIMMt4 (ORCPT ); Tue, 13 Sep 2016 08:49:56 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 13 Sep 2016 05:49:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,328,1470726000"; d="scan'208";a="8234219" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 13 Sep 2016 05:49:54 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u8DCnrLt020641; Tue, 13 Sep 2016 13:49:53 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id u8DCnraa012222; Tue, 13 Sep 2016 13:49:53 +0100 Received: (from gcabiddu@localhost) by sivswdev01.ir.intel.com with id u8DCnriN012218; Tue, 13 Sep 2016 13:49:53 +0100 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, Giovanni Cabiddu Subject: [PATCH v7 3/9] crypto: scomp - add scratch buffers allocator and deallocator Date: Tue, 13 Sep 2016 13:49:35 +0100 Message-Id: <1473770981-9869-4-git-send-email-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1473770981-9869-1-git-send-email-giovanni.cabiddu@intel.com> References: <1473770981-9869-1-git-send-email-giovanni.cabiddu@intel.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add utility functions to allocate and deallocate scratch buffers used by software implementations of scomp Signed-off-by: Giovanni Cabiddu --- crypto/scompress.c | 41 +++++++++++++++++++++++++++++++++++ include/crypto/internal/scompress.h | 2 + 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/crypto/scompress.c b/crypto/scompress.c index 9f426cc..385e1da 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,46 @@ static const struct crypto_type crypto_scomp_type; +void crypto_scomp_free_scratches(void * __percpu *scratches) +{ + int i; + + if (!scratches) + return; + + for_each_possible_cpu(i) + vfree(*per_cpu_ptr(scratches, i)); + + free_percpu(scratches); +} +EXPORT_SYMBOL_GPL(crypto_scomp_free_scratches); + +void * __percpu *crypto_scomp_alloc_scratches(unsigned long size) +{ + void * __percpu *scratches; + int i; + + scratches = alloc_percpu(void *); + if (!scratches) + return NULL; + + for_each_possible_cpu(i) { + void *scratch; + + scratch = vmalloc_node(size, cpu_to_node(i)); + if (!scratch) + goto error; + *per_cpu_ptr(scratches, i) = scratch; + } + + return scratches; + +error: + crypto_scomp_free_scratches(scratches); + return NULL; +} +EXPORT_SYMBOL_GPL(crypto_scomp_alloc_scratches); + #ifdef CONFIG_NET static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) { diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h index 8708611..a3547c1 100644 --- a/include/crypto/internal/scompress.h +++ b/include/crypto/internal/scompress.h @@ -109,6 +109,8 @@ static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, int crypto_init_scomp_ops_async(struct crypto_tfm *tfm); struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req); void crypto_acomp_scomp_free_ctx(struct acomp_req *req); +void crypto_scomp_free_scratches(void * __percpu *scratches); +void * __percpu *crypto_scomp_alloc_scratches(unsigned long size); /** * crypto_register_scomp() -- Register synchronous compression algorithm