summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2025-03-19 09:04:52 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2025-04-07 08:22:25 +0300
commit42d9f6c774790d290c175e8775ce9f1366438098 (patch)
tree692f8701d560701a346789c36c25efed57013220 /include
parentd348ebc658cdf41b922671e472a6192c2338adb4 (diff)
downloadlinux-42d9f6c774790d290c175e8775ce9f1366438098.tar.xz
crypto: acomp - Move scomp stream allocation code into acomp
Move the dynamic stream allocation code into acomp and make it available as a helper for acomp algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/internal/acompress.h33
-rw-r--r--include/crypto/internal/scompress.h28
2 files changed, 42 insertions, 19 deletions
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index 2af690819a83..ee5eff19eaf4 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -11,6 +11,10 @@
#include <crypto/acompress.h>
#include <crypto/algapi.h>
+#include <linux/compiler_types.h>
+#include <linux/cpumask_types.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue_types.h>
#define ACOMP_REQUEST_ON_STACK(name, tfm) \
char __##name##_req[sizeof(struct acomp_req) + \
@@ -53,6 +57,24 @@ struct acomp_alg {
};
};
+struct crypto_acomp_stream {
+ spinlock_t lock;
+ void *ctx;
+};
+
+struct crypto_acomp_streams {
+ /* These must come first because of struct scomp_alg. */
+ void *(*alloc_ctx)(void);
+ union {
+ void (*free_ctx)(void *);
+ void (*cfree_ctx)(const void *);
+ };
+
+ struct crypto_acomp_stream __percpu *streams;
+ struct work_struct stream_work;
+ cpumask_t stream_want;
+};
+
/*
* Transform internal helpers.
*/
@@ -157,4 +179,15 @@ static inline bool crypto_acomp_req_chain(struct crypto_acomp *tfm)
return crypto_tfm_req_chain(&tfm->base);
}
+void crypto_acomp_free_streams(struct crypto_acomp_streams *s);
+int crypto_acomp_alloc_streams(struct crypto_acomp_streams *s);
+
+struct crypto_acomp_stream *crypto_acomp_lock_stream_bh(
+ struct crypto_acomp_streams *s) __acquires(stream);
+
+static inline void crypto_acomp_unlock_stream_bh(
+ struct crypto_acomp_stream *stream) __releases(stream)
+{
+ spin_unlock_bh(&stream->lock);
+}
#endif
diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h
index fd74e656ffd2..533d6c16a491 100644
--- a/include/crypto/internal/scompress.h
+++ b/include/crypto/internal/scompress.h
@@ -9,22 +9,12 @@
#ifndef _CRYPTO_SCOMP_INT_H
#define _CRYPTO_SCOMP_INT_H
-#include <crypto/acompress.h>
-#include <crypto/algapi.h>
-#include <linux/cpumask_types.h>
-#include <linux/workqueue_types.h>
-
-struct acomp_req;
+#include <crypto/internal/acompress.h>
struct crypto_scomp {
struct crypto_tfm base;
};
-struct crypto_acomp_stream {
- spinlock_t lock;
- void *ctx;
-};
-
/**
* struct scomp_alg - synchronous compression algorithm
*
@@ -33,14 +23,10 @@ struct crypto_acomp_stream {
* @compress: Function performs a compress operation
* @decompress: Function performs a de-compress operation
* @base: Common crypto API algorithm data structure
- * @stream: Per-cpu memory for algorithm
- * @stream_work: Work struct to allocate stream memmory
- * @stream_want: CPU mask for allocating stream memory
+ * @streams: Per-cpu memory for algorithm
* @calg: Cmonn algorithm data structure shared with acomp
*/
struct scomp_alg {
- void *(*alloc_ctx)(void);
- void (*free_ctx)(void *ctx);
int (*compress)(struct crypto_scomp *tfm, const u8 *src,
unsigned int slen, u8 *dst, unsigned int *dlen,
void *ctx);
@@ -48,9 +34,13 @@ struct scomp_alg {
unsigned int slen, u8 *dst, unsigned int *dlen,
void *ctx);
- struct crypto_acomp_stream __percpu *stream;
- struct work_struct stream_work;
- cpumask_t stream_want;
+ union {
+ struct {
+ void *(*alloc_ctx)(void);
+ void (*free_ctx)(void *ctx);
+ };
+ struct crypto_acomp_streams streams;
+ };
union {
struct COMP_ALG_COMMON;