From: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Subject: [PATCH v7 3/9] crypto: scomp - add scratch buffers allocator and deallocator
Date: Tue, 13 Sep 2016 13:49:35 +0100 [thread overview]
Message-ID: <1473770981-9869-4-git-send-email-giovanni.cabiddu@intel.com> (raw)
In-Reply-To: <1473770981-9869-1-git-send-email-giovanni.cabiddu@intel.com>
Add utility functions to allocate and deallocate scratch buffers used by
software implementations of scomp
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
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 <linux/slab.h>
#include <linux/string.h>
#include <linux/crypto.h>
+#include <linux/vmalloc.h>
#include <crypto/algapi.h>
#include <linux/cryptouser.h>
#include <net/netlink.h>
@@ -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
--
1.7.4.1
next prev parent reply other threads:[~2016-09-13 12:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 12:49 [PATCH v7 0/9] crypto: asynchronous compression api Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 1/9] crypto: add " Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 2/9] crypto: add driver-side scomp interface Giovanni Cabiddu
2016-09-13 12:49 ` Giovanni Cabiddu [this message]
2016-09-13 12:49 ` [PATCH v7 4/9] crypto: acomp - add support for lzo via scomp Giovanni Cabiddu
2016-09-20 9:26 ` Herbert Xu
2016-09-20 12:23 ` Giovanni Cabiddu
[not found] ` <20160920115140.GA12332@sivswdev01.ir.intel.com>
2016-09-22 9:22 ` Herbert Xu
2016-09-22 22:54 ` Giovanni Cabiddu
2016-09-23 15:05 ` Herbert Xu
2016-09-26 17:27 ` Giovanni Cabiddu
2016-09-27 3:07 ` Herbert Xu
2016-09-13 12:49 ` [PATCH v7 5/9] crypto: acomp - add support for lz4 " Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 6/9] crypto: acomp - add support for lz4hc " Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 7/9] crypto: acomp - add support for 842 " Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 8/9] crypto: acomp - add support for deflate " Giovanni Cabiddu
2016-09-13 12:49 ` [PATCH v7 9/9] crypto: acomp - update testmgr with support for acomp Giovanni Cabiddu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473770981-9869-4-git-send-email-giovanni.cabiddu@intel.com \
--to=giovanni.cabiddu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).