@@ -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)
{
@@ -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
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(-)